print('print("print")') output:print("print") but print("print("print")") output:error. Why? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

print('print("print")') output:print("print") but print("print("print")") output:error. Why?

13th Apr 2020, 8:20 PM
Ayushi Negi
6 Answers
+ 16
It if for the quotation mark ("") look, case 1: you can put a single quotation under a double quotation and also a double quotation under a single quotation. Here, you put a double under a single. So, the first pair (single) is taken as the normal syntax of the print function which we use to declare strings. and the second pair (double quotation) is displayed in the output. case 2: you must put a \ to display a double qoute in the output if the string was declared under a double quotation. your first print satement is the normal function to display output. second "print" and "(" goes under a string. So, the first str here is "print(" then the string was closed and was reopened for ")". At the middle "print" goes undeclared and an error occurs. Write case 2 like this, >>>print("print(\"print\")") output : print("print") A very good question tho👍
13th Apr 2020, 8:36 PM
M Tamim
M Tamim - avatar
+ 7
At this point... print("print(" ... Python thinks that the string is finished. I mean, wouldn't you, as a computer? (They're rather dumb.) 'Read till you find another ", that's the end of the string.' So Python did that, not questioning your orders. Human say, PC do. Then, suddenly, there comes something like... print... ... that makes no sense under the assumption that the string is over. So you get an error.
13th Apr 2020, 8:36 PM
HonFu
HonFu - avatar
+ 2
\" will help. because python thinks " ends at first bracket.
13th Apr 2020, 8:34 PM
Shafiqur Rahman
0
print("print("print")") print function in python gives the output for lines under the double quotation(print("print(") ,as per above code. And the remaining(print")") )is treated as invalid,because there is print word without quotes.
14th Apr 2020, 9:06 AM
Basavaraj Patil
Basavaraj Patil - avatar
0
print("print("print")") is same as print ("a" b "c") and you cant print "" if you use same symbol for printing something
14th Apr 2020, 7:37 PM
Michal Choma
Michal Choma - avatar
0
you can write print('print ("print")') the output will be: print ("print")
16th Apr 2020, 8:26 AM
Mazen Mahmah
Mazen Mahmah - avatar