Python string or string in python is series of characters or element.In python idle or jupyter notebook a string is written as

a=’apple’

any element between single quotes or double quotes will create string in python.

a is a string.

a[0]

Output=’a’

as shown in image below

string in pythonString In Python

 

 Methods of String in Python:

String  has many functions that can be used for working with strings.These methods make it easy to work with strings in Python, whether you’re formatting, searching, or manipulating text.

1 Str.Capitalize: To make the first character have upper case and the rest lower case.

2.Str.casefold: It Return a version of the string suitable for caseless comparisons.

3. Str.Center:It will return padded centered string.

4. Str.Count: To count number of times an object occurring in given string.

5.Str.encode:It Returns encodes version of string if not mentioned then in UTF 8 standard.

6.Str.endswith:It returns True or False if specified object matches with suffix in string.

7.Str.expandtabs:Will return copy of string in which all tab char are replaced with spaces.

8.Str.Find: It returns index of the substring which is to be find.

9.Str.Format: It returns the formatted version of string.

10. Str.Format_map: It takes values as dictionary and returns formatted version of string.

11. Str.index: It will returns the lowest index of string where substring is found in string.

12. Str.isalnum: It returns True if characters in given string are alphanumeric.

13. Str.isalpha:It returns True if characters in string are alphabetic.

14.Str.isdecimal:It returns True if characters in string are decimal numbers.

15.Str.isdigit: It returns True if characters in string are digit else returns False.

16.Str.isidentifier:It returns True if string is valid identifier else returns False.

17.Str.islower: It returns True if element in string are lowercase else returns False.

18. Str.isnumeric:It returns true if element in string are numeric else returns False.

19.Str.isprintable: It returns true if element in string are printable else returns False.

20. Str.isspace: It returns True if element in string are white spaces or space.

21. Str.istitle: It returns True if first character in string are upper case and rest are lower case else False.

22.Str.isupper: It returns True if all character in string are upper case else False.

23. Str.Join: It returns a string which is the concatenation of the two strings.

24. Str.ljust: It returns left justified string.

25.str.rjust:It returns right justified string.

26. Str.lower: It returns all letters in lower case.

27. Str.upper: It returns all elements in capital letters.

28. Str.lstrip:It removes all leading white spaces.

29.Str.rstrip:It removes all trailing white spaces.

30.Str.partition: It separate the string with separator and returns tuple with separator.

31.Str.maketrans:It returns translation table.

32.Str.replace: It will replace the old word with the new one in string.

33.Str.rpartition:It separate the string with separator and returns tuple with separator starting from end.

34.Str.split: It will split the string by given separator starting from beginning.

35.Str.rsplit: It will split the string by separator starting from end.

36. Str.startswith:It returns True when string starts with specified character else False.

37.Str.title: It turns first character of the word in capital letter.

38.Str.swapcase:It returns all letters in small case to capital and vice-versa.

39.Str.zfill:It pads a string with zero on left side, to return a string of specified width.

All above mentioned methods are used for string manipulation or working with string by clicking on link above you can learn more in details.

By SC

29 thoughts on “String In Python”

Leave a Reply

Your email address will not be published. Required fields are marked *