I Have a Question About Strings




In the previously listed lesson I was asked to write str( ) before 3.14 in order to correct the sentence and turn it into a string, so it can be printed.

My question is why did I have to do that when I could have easily just put quotation marks around the number and it would’ve been successfully turned into a string, therefore it would’ve been printed?

Am I missing something here?

Is this just an example of another way to turn sentences into strings, if so in what ways would I have no other choice but to use it?

Python Noob Alert

what if the number was user input? Or from a database? Or fetched from a website (data scraping)? This lesson teaches a concept that is important


Thank you for your reply.
I just started learning code today, so I must admit I didn’t really understand what you just said.
Is there any way you could be more specific?


well, currently you hard-coded the value (3.14) into your program, so yes, you can put quotation marks, but if the value comes from a database and is stored in a variable, you can’t put quotation marks around the value, so you will have to use str()


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.