By Lenin Mishra
If you prefer to watch Youtube videos over reading blogs, check out our video on Python strings here.
What are strings in Python?
Strings are amongst the most popular data types in Python. A string can be defined as a sequence of characters.
Strings can be created by enclosing characters inside a single quote, double-quotes and triple quotes.
# Single Quotes my_string = 'Pylenin' print(my_string) # Double Quotes my_string = "Pylenin" print(my_string) # Triple Quotes # can be extended over multiple lines my_string = """Check out Pylenin for Python related blogs and videos""" print(my_string)
Pylenin Pylenin Check out Pylenin for Python related blogs and videos
As you can see in the code above, we are assigning a string to a variable. It is done with the variable name followed by an equal sign and the string.
Unless necessary, try not to use triple quotes for strings. It is generally used for writing docstrings in your Python code, which acts like a documentation.
- How to access characters in a Python string?
- How to replace characters in a string in Python?
- How to concatenate strings in Python?
- How to iterate through a string in Python?
- Check if a Substring is Present in a Given String in Python
- Escape sequences in Python String
- Python String Formatting - The Definitive Guide
- Commonly used Python string methods