What are Strings in Python?

A string is a sequence of characters. Strings are arrays of bytes representing Unicode characters. However, Python does not have a character data type, a single character is simply a string with a length of 1.

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.

Example:

defining strings in Python

# all of the following are equivalent

my_string = 'Hello'
print(my_string)

my_string = "Hello"
print(my_string)

my_string = '''Hello'''
print(my_string)

# triple quotes string can extend multiple lines

my_string = """Hello, welcome to
           the world of Python"""
print(my_string)

Output:

Hello
Hello
Hello
Hello, welcome to
           the world of Python