Python String:
Note: In the result, the line breaks are inserted at the same position as in the code.
String in python are surrounded by either single quotation marks, or double quotation marks.
"hello" and 'hello' are same and both are string.
Assigning String to a Variable:
a = "Hello"
print(a)
print(a)
Output:
Hello
Multi-line Strings:
multi-line string can be assign to a variable by using three double or single quotes:
Example:
a = """Hey I am
a python
Developer."""
print(a)
print(a)
Result:
Hey I am
a python
Developer.
Note: In the result, the line breaks are inserted at the same position as in the code.
String are Arrays
String in Python are arrays of bytes representing uni-code characters.
Square brackets can be used to access elements of the string.
Example:
a = "Python,Developer"
print(a[1])# note that (,) is also counted
print(a[1])# note that (,) is also counted
Result:
y
0 Comments