Visit: https://a2zcareers.viden.io
String literals in python are surrounded by either single quotation marks, or double quotation marks.
'hello' is the same as "hello".
You can display a string literal with the print()
function:
print("Hello")
print('Hello')
Assigning a string to a variable is done with the variable name followed by an equal sign and the string:
a = "Hello"
print(a)
You can assign a multiline string to a variable by using three quotes:
You can use three double quotes:
a = """Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua."""
print(a)
Or three single quotes:
a = '''Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.'''
print(a)