String And String Method
String: sequential data sequence ofcharacter /element present inside a single/duable/triple quates (‘ ’),(“ “),(‘’’ ‘’’).
properties of string:
- sequence data.
- immutable data
if data can controled one we cont change data
i.adding a new element
ii.replasing are existing
iii.deliting on existing
Name error: In python is an error that occurs when you try to use a variable or name that has not been defind.
Type error: is an error that occurs when you perfrom an operation on an incorrect data type.
Index error: in python accures when try to access an index that does not exist in a list string or tuple.
string method (or) function:
string .method
Exception attribute error: is an error that accrues when you try to access an attribute or method that does not exist for an object.
- lowercase (): string method is used to convert all the upper-case characters to lower case and other character are ignored.
2. uppercase(): string method is used to convert all the lower case to upper case and other characters are ignored.
3. swap(): string Methode is used to convert upper case to lower case and lower case to upper case.
4. capitalize (): is used to convert the first character /element into upper case rest of the character into lowercase.
5. title(): is used to convert the first character of a word in side a string in to upper case and rest of the character of the word into lowercase and rest of the charecter will be ignored.
→this method convert the first letter of each word in a string to uppercase and the remaining letters to lowercase.
6. count(): which is used to a specific character occured how money times in a string →left to right.
7. Index(): it is used to give the index value of a substring accuring of the first accurance python left to right — — ->
→ in index any character does not present it will give the error called “value error”
8. find(): In python, the find() method is used to search for a particular character or substring in a string.
it returns the lowest index (position)where the sub string is found.
Ex: var1=”hello world”
var1.find(“world”)
In find character is not present it will show the result is -1
9. strip (): substring by using which we can remove the character in the substring.
Ex:
10. l-strip(): substring by using which we can remove the character in the left side of substring.
Get Vravinaik Boje’s stories in your inbox
Join Medium for free to get updates from this writer.
Ex:
11. r-strip(): substring by using which we can remove the character in the right side of substring.
Ex:
12. split(): by using which can divide/split an entire string into substring.
Ex: “python java c c++”.split(“ “)
14. replace (): We can replace any character or a sequence of character inside a string with author character.
Ex:
15. r-find (): this method is used to find the last occurrence of a substring in a string.
→it search's from right to left.
→it returns the highest index position
→if the substring is not found, it returns -1
Ex:
16. r-index (): this method returns the highest(last) index position of a specified character or substring in a string.
→in simple words, it searches for a character from right to left.
Ex:
17. Is upper(): In which is used to check all the alphabets are in uppercase or not.
Ex:
18. is lower (): In which is used to check all the alphabets are in lowercase or not. if given letters are all small it will gives →True otherwise it will gives false.
Ex:
19. is title (): is a string method that checks whether a string is in title case
→it returns True if each word starts with an uppercase letter and the remaining letters are lowercase.
→it returns False if the string is not in title case.
Ex:
20. is digit (): the method checks whether all characters in a string are digits (0–9).
→it returns True if all characters are digits.
→it returns False if the string contains letters, space, or special characters
Ex:
21. is alpha (): method checks whether all character in a strings are alphabets (letters).
→returns True if all character are letters
→returns False if the string contains numbers, space, or special characters
Ex:
22. is alnum(): method checks whether all characters in a string are alphabets or numbers.
→returns True if the string contains only letters and numbers.
→returns False if it contains spaces or special characters.
Ex:







