What is String in Python
A string is a sequence of characters, where each character has a unique position/index. The index of string starts from 0 to length-1 in forward direction and -1,-2,-3 …. Length-1 in backward direction.
How to create a string in Python?
Strings can be created by enclosing characters inside a single quote or double quotes. Even triple quotes can be used in Python but generally used to represent multiline strings and docstrings.
# all of the following are equivalent
Example:
n = ‘Hello’
print(n)
output:
Hello
Example:
n = “Hello”
print(n)
output:
Hello
Example:
n = ”’Hello”’
print(n)
output:
Hello
Example:
# triple quotes string can extend to multiple lines
n = “””Hello, welcome to
the world of Python”””
print(n)
Output:
Hello, welcome to
the world of Python