0

Python beginner Q: It is only when we use " or such (and/or print statement) that it will not calculate it?

It is only when we use " or such (and/or print statement) that it will not calculate it? And if the answer is no? For example when (X+Y) in my previous lesson it was the case that there was a calculation.

5th Feb 2022, 9:20 AM
Mohammed PressTV.ir Fan
Mohammed PressTV.ir Fan - avatar
8 Answers
+ 4
I'm not entirely sure if this what you're asking. But (mathematical) expressions are always evaluated unless they are given as a string, i.e. within single or double quotes. E.g.: print(1 + 2) # prints "3" because the expression is evaluated and the result is printed. print("1 + 2") # prints "1 + 2" because the expression is given as a string, i.e. a sequence of symbols with no regard to their meaning.
5th Feb 2022, 9:44 AM
Simon Sauter
Simon Sauter - avatar
+ 3
What do you mean? Anything surrounded by " " is a string. A string is not an equation it's a string. Can you give some better examples?
5th Feb 2022, 9:25 AM
Slick
Slick - avatar
+ 3
"Evaluated" is the more technical term and it applies to all kinds of expressions, not just mathematical ones (e.g. logical expressions). Of course in this context you can also just use "calculated".
5th Feb 2022, 10:00 AM
Simon Sauter
Simon Sauter - avatar
+ 3
You can use three quotes (either three single or three double quotes) for multi-line strings.
5th Feb 2022, 10:01 AM
Simon Sauter
Simon Sauter - avatar
+ 2
Simon Sauter If you don't mind I'll ask a little more; triple " is also possible right? And could I use the word calculated instead of evaluated here? Why would evaluated be better/more appropriate here (if at all)?
5th Feb 2022, 9:53 AM
Mohammed PressTV.ir Fan
Mohammed PressTV.ir Fan - avatar
+ 1
Thank you for your answer. So besides a string, it will always be calculated (the values/numbers) if it's written correctly? Or are there besides string other ways? Something like that, sorry.
5th Feb 2022, 9:34 AM
Mohammed PressTV.ir Fan
Mohammed PressTV.ir Fan - avatar
+ 1
Thank you. That was indeed my main question.
5th Feb 2022, 9:47 AM
Mohammed PressTV.ir Fan
Mohammed PressTV.ir Fan - avatar
0
There are lots of ways. What is the basis of this question? Like what made you ask it?
5th Feb 2022, 9:35 AM
Slick
Slick - avatar