Can you check my code and explain how the outcome came to be. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can you check my code and explain how the outcome came to be.

I am new to python and started the course for begginers I am currently at the strings lesson. Reading the comment on the lesson about the quotes and how to use I started to try to test their code with some additions of my own and need someone to help explain the outcomes to me. I know where the errors are and how to fix them but i need to know why python behaves that way. look at example 5 and 9 and explain to me the outcome if possible.(the extra quotes at the beginning of the code are turned to a string, while the last two extra quotes at the end are ignored can some one tell me why if possible). https://code.sololearn.com/ctxCN22MUMxr/?ref=app

20th Aug 2021, 3:54 PM
Taha Bahaa Eldin
13 Answers
+ 4
Strings must be enclosed in identical pair of quotes upto triple quotes. Like, print('Hello') print("Hello") print('''Hello''') in example 5, you started with single quote, so python considers the end to also be a single quote. The remaining pair of quotes is taken to be another string. in example 9, Same explanation but with triple quotes. You started with triple quotes, hence python searches for another triple quote to terminate the string. The last set of single quotes is again taken as a separate string. Hope this helps. https://code.sololearn.com/csK5q9mgMZDe
21st Aug 2021, 6:55 AM
Priyadarshan N S
Priyadarshan N S - avatar
+ 2
Remove the 2 extra Quotes... Because, You Have Written Multiline String And that 2 quots gets added to it...
20th Aug 2021, 4:01 PM
Sancho Godinho
Sancho Godinho - avatar
+ 2
Just Add a Space between your 3 & 2 quotation marks :- print(''' ''Always look on the bright side of life'' ''')
20th Aug 2021, 4:12 PM
Sancho Godinho
Sancho Godinho - avatar
+ 2
In The Second One, You Have Use A New Line And Not Used A Multiline String... Use This in Your Second Line :- print('Always look on the\nbright side of life') As \n Defines New Line in A Non-Multiline String...
20th Aug 2021, 4:15 PM
Sancho Godinho
Sancho Godinho - avatar
+ 2
That's A Really Hard Question to Answer...
20th Aug 2021, 4:28 PM
Sancho Godinho
Sancho Godinho - avatar
+ 2
Sancho Godinho thank you for your answer again it helped me to understand a bit about the behavioral process that python uses. but still if we consider what you say why the first extra quote or two quotes are turned into a string will the quotes at the end of the sentences are ignored and not turned into quotes. especially after you put the exclamation mark just before the last quote and it was read by the program and turned into string normally while not turning the quotes before it. and also in the last example you put the exclamation mark after the fourth quote why not after the third isn't it suppose to be equal on both side, neither the 4 quotes that is before the ! is equal to the number of quotes in the beginning , or the 1 quote after ! is equal to the number of quotes at the beginning.
21st Aug 2021, 10:14 AM
Taha Bahaa Eldin
+ 2
T B With example: print(""" ... Text ... """) So you write your text AND if Is a input() you can write in the input() Ex: input=input("...") So you can tell your text for tell the information
22nd Aug 2021, 1:54 AM
CGO!
CGO! - avatar
+ 1
Sancho Godinho yeah thanks a bit clearer. but if I may ask why when I don't add spaces between my 3 & 2 quotation marks the first two quotation marks still appear as a string while the last two don't.
20th Aug 2021, 4:27 PM
Taha Bahaa Eldin
+ 1
Sancho Godinho It is okay you are really helped clarify some of my questions I feel I have abit more deeper understanding of the language now. maybe someone who knows the answer will leave a reply in the future.
20th Aug 2021, 4:35 PM
Taha Bahaa Eldin
+ 1
This should help you understand better. https://code.sololearn.com/cWlYL35wsspv
21st Aug 2021, 12:26 PM
Priyadarshan N S
Priyadarshan N S - avatar
+ 1
PRIYADARSHAN N S why sometimes python turns the first two extra quotes into strings while the last extra two quotes at the end of the string are ignored. I want to add that your code is very helpful but it just adds to my questions that all the whole point from my question is to understand how python think so I can get a deeper understanding of the language.
21st Aug 2021, 12:39 PM
Taha Bahaa Eldin
0
Sancho Godinho thank you sir i rewrote the description so my question is abit more clear. I am not asking where the errors are I know where they are and how to fix them I just want an explanation for the behaviour of python like why did it decide to ignore the last quotes in example 5 and 9 but turned the first extra quotes into string.
20th Aug 2021, 4:08 PM
Taha Bahaa Eldin
0
★Caleb Guerra Ortega★ sorry can you explain a bit more. and sometimes in the codes like in example 5 and 9 there are extra quotes that are turned into strings(at the beginning of the string input) while there are extra quotes being ignored(at the end of the string input).
22nd Aug 2021, 3:37 AM
Taha Bahaa Eldin