Let’s talk about this data type str which stands for strings.
A string is simply a piece of text for example a string can be written with quotation marks i.e ‘Hello World’.
We can also make strings with double quotes, this is also a valid string i.e. “Hello World”.
Python does not support character data type, one character is also treated as a string of length one.
x = "Hello World" y = 'Python Coding' print(x) print(y)
Hello World Python Coding
Multiple Line String
We can’t write a paragraph of multiple lines using single or double quotes, so there is a triple quotation method to write a big paragraph of multiple lines.
x = '''This is a big paragraph by using triple qoutation in Python. ''' print(x)
This is big paragraph by using triple qoutation in Python.
**We also use escape characters in between big paragraphs.
|\a||Bell or alert|
|\nnn||Octal notation, where n is in the range 0.7|
|\xnn||Hexadecimal notation, where n is in the range 0.9, a.f, or A.F|
Accessing Values in Strings
We can access characters or substring from a string using index number. This is also called String Slicing. For example:
x = 'Python' #012345 print(x) print(x[0:4]) #start index : end index+1
Adding two or more string is called String Concatenation. This only works with Strings, we can’t a string and a number.