Python Language / Python Strings

It is collection of unicode characters (arrays of bytes) and surrounded by either single / double quotation marks and printed on screen using print function. Python Strings elements are accessed elements using string Square brackets.

Example
1. 'Python World’ is the same as”Python World ".
print("Python World").
2.Let us take a string p = "Python World"

String Functions and their properties with examples
Sting Functions and properties Used to Example Output
string Element Accessing Access any element of the string. p  = "Python  World" 
print(p[0])
print(p[1])
P
y
Substring Gets a part of string print(p[0:4]) Pyth
len(p) Give length of string print(len(a)) 13
lower() Convert string to lower case. print(p.lower()) python  world
upper() Convert string to upper case. print(p.upper()) PYTHON  WORLD
replace() Replace a character with other character in the complete string print(p.replace("P", "H")) Hython  World
split() splits the string into substrings p = "Python, World!"
print(p.split(","))
['Python', ' World!']


Home     Back