[metaslider id="213"]

Str.capitalize() returns a copy of the string containing first character capitalized and the rest in lowercased

x = "hello"



Output: Hello

Str.lower() returns a string in which all characters are in lowercased

x = "HELLO"


Output: hello

Str.upper() returns a string in which all characters are in uppercased

x= "hi uzair"


Output: HI UZAIR

Str.strip() returns a copy of string with leading and trailing characters removed. In this case white characters are removed

s = '   hello world   \n'


Output: hello world

Str.split() return a list of words of the string s

s = 'Lets split the words'
s.split(' ')

Output: [‘Lets’, ‘split’, ‘the’, ‘words’]

If we want to get a chunk or slice or substring from a  string we can do this by Slicing

word = "Howdy"


Output: Ho


Output: How

We can also find a substring in a string

'He' in word

Output: False

'How' in word

Output: True

String in Python

Post navigation

Leave a Reply

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