For excercise 1.3 the use of double quotes seems to be problematic, however if I use single quote followed by double quotes then I get the expected output. for Example print '"Hello world"' get the desired result, but print ""Hello World"" does not work
only " and ' are good, not triple quote or more. If you use more quotes then python must know which one shows start and end of quotations. So your firs example work because python thinks it start with ' and end with ' and "" are quotations inside string. For second you have only "" so python doesn't know where it starts and ends and that is python syntax error to write code like that. Hope this helps. It was talked about this in videos (Recitation). Cheers
""bla"" means "" null string, bla varable, "" null string. "\"bla\"" Escaped quotes work too. What if you need to use both ' and " inside the quote? The excaped quotes helps with this: "\"I'm not sure which set is best,\" he said." '"I\'m not sure which set is best," he said.' You escape what you are using.
If you want your output to have quotes you have to use the opposite type. So if you want 'Hello World' you need to have " 'Hello World' " and if you want "Hello World" you need to have ' "Hello World" ' This is because when the program runs, the first time it sees a quote it will the scan through the text until it finds the NEXT MATCHING quote and print everything in between it. Having two of the same type next to each other will print what is in between them, which is nothing.
Thanks, that helps a lot, I sort of figured this out anyway but it is good to see that this behaviour is expected or normal. Cheers
Join our real-time social learning platform and learn together with your friends!