educative.io

Educative

Inserting strings in a string

why is this code below printing python without the “s” if % = python
[string1 = “I like %s” % “Python”
print(string1) # ‘I like Python’]


Type your question above this line.

Course: https://www.educative.io/collection/10370001/5473789393502208
Lesson: https://www.educative.io/collection/page/10370001/5473789393502208/5461228968738816

1 Like
string1 = "I like %" %" Python"
print(string1) 

Won’t work it is a syntax error

string1 = "I like " "Python"
print(string1)

Prints I like Python. This is because of implicit concatenation. Python allows both single and double quotes and this behavior is introduced to allow concatenation of stings defined in either.
Try this

string1 = "I like " 'Python'
print(string1)
1 Like

thank you