Strings
If you want to use text in Python, you have to use a string.
A string is created by entering text between two single or double quotation marks.
When the Python console displays a string, it generally uses single quotes. The delimiter used for a string doesn't affect how it behaves in any way.>>> "Python is fun!"
'Python is fun!'
>>> 'Always look on the bright side of life'
'Always look on the bright side of life'
Newlines !!
Python provides an easy way to avoid manually writing "\n" to escape newlines in a string. Create a string with three sets of quotes, and newlines that are created by pressing Enter are automatically escaped for you.>>> """Customer: Good morning.
Owner: Good morning, Sir. Welcome to the National Cheese Emporium."""
'Customer: Good morning.\nOwner: Good morning, Sir. Welcome to the National Cheese Emporium.'There is another string type in Python called docstrings that is used for block commenting, but it is actually a string. You will learn about this in future lessons.
Comments
Post a Comment