What is String in Python ?

A String is a combination of sequence characters. Strings can be created in Python by enclosing them around quotes. Python is designed in such a way that single or double quotes are one and the same, both work in similar way. The index of the string starts from Zero.

Example :

Str1 = “Hello python!!”

Str2 = ‘Python string example’

  1. len(String) : Length method will return the string length count.

Example :

Here the length of the string “Python language” is 15 because index of the string

Starts with zero.

  1. lower() : Converts the complete string into lower case.

Example :

Here the string “PYTHON language” is converted to lower case irrespective of the current case.

3.Upper() : Converts the complete string into upper case.

Example :

str = “python langUAGE”

Print(str.upper())

Here the string “Python language” is converted to upper case irrespective of the current case.

4.Replace() : Replace method will replace the existing text with the new text as specified.

Example : a = “sam1234sam4321”

Print(a.replace(“sam”,”john”))

Here the string “sam1234sam4321” is converting the “sam” text occurence to “John” in the string.

5.Isdigit() : Isdigit method will return true, if the string contains numbers or else will return false.

Example :

Here is the string c contains only numbers the output will be true or else the output will be false.

6.Isalpha() : isalpha method will return true, if the string contains only alphabets without spaces and digits.

Example :

First example will return true and second example will return false.

Leave a Comment

Your email address will not be published.