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.
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.
+ 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?
+ 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".
+ 3
You can use three quotes (either three single or three double quotes) for multi-line strings.
+ 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)?
+ 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.
+ 1
Thank you. That was indeed my main question.
0
There are lots of ways. What is the basis of this question? Like what made you ask it?