Sitemap

String And String Method

6 min read2 days ago

--

String: sequential data sequence ofcharacter /element present inside a single/duable/triple quates (‘ ’),(“ “),(‘’’ ‘’’).

properties of string:

  1. sequence data.
  2. 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.

Press enter or click to view image in full size
Press enter or click to view image in full size

Index error: in python accures when try to access an index that does not exist in a list string or tuple.

Press enter or click to view image in full size

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.

Press enter or click to view image in full size
  1. lowercase (): string method is used to convert all the upper-case characters to lower case and other character are ignored.
Press enter or click to view image in full size

2. uppercase(): string method is used to convert all the lower case to upper case and other characters are ignored.

Press enter or click to view image in full size

3. swap(): string Methode is used to convert upper case to lower case and lower case to upper case.

Press enter or click to view image in full size

4. capitalize (): is used to convert the first character /element into upper case rest of the character into lowercase.

Press enter or click to view image in full size

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.

Press enter or click to view image in full size

6. count(): which is used to a specific character occured how money times in a string →left to right.

Press enter or click to view image in full size

7. Index(): it is used to give the index value of a substring accuring of the first accurance python left to right — — ->

Press enter or click to view image in full size
Press enter or click to view image in full size

→ in index any character does not present it will give the error called “value error”

Press enter or click to view image in full size

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”)

Press enter or click to view image in full size

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:

Press enter or click to view image in full size

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:

Press enter or click to view image in full size

11. r-strip(): substring by using which we can remove the character in the right side of substring.

Ex:

Press enter or click to view image in full size

12. split(): by using which can divide/split an entire string into substring.

Ex: “python java c c++”.split(“ “)

Press enter or click to view image in full size

14. replace (): We can replace any character or a sequence of character inside a string with author character.

Ex:

Press enter or click to view image in full size

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:

Press enter or click to view image in full size
Press enter or click to view image in full size

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:

Press enter or click to view image in full size

17. Is upper(): In which is used to check all the alphabets are in uppercase or not.

Ex:

Press enter or click to view image in full size

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:

Press enter or click to view image in full size

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:

Press enter or click to view image in full size

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:

Press enter or click to view image in full size

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:

Press enter or click to view image in full size

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:

Press enter or click to view image in full size

--

--