String Concatenation
first = "Hello"
second = "World"
print(first + second)
String Concatenation
first = "Hello"
second = "World"
print(first + second)
HelloWorld
Concatenating Numbers
text = "Your total is $"
value = 2.75
print(text + str(value))
Concatenating Numbers
text = "Your total is $"
value = 2.75
print(text + str(value))
Your total is $2.75
Concatenating Numbers
text = "Your total is $"
value = 2.75
print(text + value)
Concatenating Numbers
text = "Your total is $"
value = 2.75
print(text + value)
Traceback (most recent call last):
File "tutor.py", line 3, in <module>
print(text + value)
TypeError: must be str, not float
Repeat
word = "repeat"
print(word * 2)
print(word * 4)
Repeat
word = "repeat"
print(word * 2)
print(word * 4)
repeatrepeat
repeatrepeatrepeatrepeat
Escape
sentence = "Hello from "the little apple!""
print(sentence)
Escape
sentence = "Hello from "the little apple!""
print(sentence)
File test.py, line 1
sentence = "Hello from "the little apple!""
^
SyntaxError: invalid syntax
Escape
sentence = "Hello from \"the little apple!\""
print(sentence)
Escape
sentence = "Hello from \"the little apple!\""
print(sentence)
Hello from "the little apple!"
Single & Double Quotes
sentence = 'Hello from "the little apple!"'
print(sentence)
Hello from "the little apple!"