In Python, a string is a sequence of characters enclosed inside quotation marks. You can use either single quotes ('
), double quotes ("
), or triple quotes ('''
or """
) to represent a string. For instance:
text = 'Hi there'
print(text) # Output: Hi there
Here, 'Hi there'
is a string containing the characters 'H'
, 'i'
, space (' '
), 't'
, 'h'
, 'e'
, 'r'
, and 'e'
. Strings are versatile and widely used in Python for various purposes.
quote = "To be or not to be, that is the question."
print(quote) # Output: To be or not to be, that is the question.
In this example, the string "To be or not to be, that is the question."
is assigned to the variable quote
. Strings can contain letters, digits, spaces, punctuation, and special characters.