How to use backslash on double quote | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

How to use backslash on double quote

print('I\'m learning Python!') print("A number enclosed in double quotes: "42"")

11th Apr 2021, 6:35 PM
Travis Business
Travis Business - avatar
2 Respostas
+ 1
The backslash escape characters with special meanings. n becomes a newline \n, and quotes becomes a character without the ā€˜end the stringā€™ meaning the quote normal gets inside a string, if the string began with the same kind of quote. So it becomes an ordinary character with a backslash \" . s0 = "\"" becomes a string with one character: len(s0) = 1 and print(s0) gives: " There is nothing special with ā€œ (duoble qoute) comparing to ā€˜ (singel quote). So to enclose a number in quotes you can escape them: s1 = "\"42\"" or: s2 = '"42"' In the last one the string starts and ends with single qutoes, so the double quotes becomes ordinary characters inside the string.
11th Apr 2021, 7:32 PM
Per Bratthammar
Per Bratthammar - avatar
0
This line doesn't produce errors. It is okay as it is: print('I\'m learning Python!') This line was producing an error. print("A number enclosed in double quotes: "42"") The corrected syntax is as follows: print("A number enclosed in double quotes: \"42\"")
11th Apr 2021, 7:27 PM
EO4Wellness
EO4Wellness - avatar