What is the difference between the value and the variable name if the variable message and value Game over print("Game over") | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the difference between the value and the variable name if the variable message and value Game over print("Game over")

Variable print

12th Jul 2023, 4:44 PM
Asep Sujana
Asep Sujana - avatar
8 Answers
+ 5
print() is a function, not a variable
12th Jul 2023, 4:57 PM
Lisa
Lisa - avatar
+ 3
in your example "message" is a string as can be seen from the "". there is no variable called message
12th Jul 2023, 4:59 PM
Lisa
Lisa - avatar
+ 3
Ugulberto Sánchez you have confused double-quotation marks (") with commas (,). Asep Sujana strings are denoted by single- or double-quotation marks (not commas).
12th Jul 2023, 8:08 PM
Brian
Brian - avatar
+ 3
What is the difference between the value and the variable name if the variable message and value Game over print("Game over") instead of print("message") message = “Game Over” print(message) #Prints the context of the variable. print(“Game Over”) #Prints the string. In this example it does not make much of a difference since the result is the same. But if you have to write a more sophisticated code then using a variable would be more beneficial. Example: player_score = 1000 message = False if player_score >= 1000:     message = True if message:     print("Game Over!") else:     print("Continue playing!") It would make more sense to use game_over as variable instead of message. But for demonstration I have used message as variable, you may check if message is true or false with print(message)
12th Jul 2023, 8:24 PM
Chris Coder
Chris Coder - avatar
+ 1
Asep Sujana, "string" datatype is surrounded by double question marks and it is interpreted as text for example: "hello!" to call a variable, use its name WITHOUT double question marks for example: my_var = 34 print("my_var") -> prints my,_var in the console print(my_var) -> prints 34 Doy you understand?
12th Jul 2023, 5:01 PM
Ugulberto Sánchez
Ugulberto Sánchez - avatar
+ 1
#Variable msg = "hi" print(msg) #No variable print("hi") These two provide the same result, but it is not always the same. - We use the first one to get the result of performing stuff or complex things. It can have multiple different results, instead of knowing the answers already and write it down(This is useless when interacting with user input) - We use the second one, to be sure that it should appear everytime executing the code. Example: name = input() print('Hi",name) //This would show "Hi" everytime executing, but the "name" variable can be different strings each time running, because it is used to get user input. another example(for loop): n = int(input()) for x in range(0,n): print("Hello",x)
12th Jul 2023, 5:53 PM
Dragon RB
Dragon RB - avatar
0
What is the difference between the value and the variable name if the variable message and value Game over print("Game over") instead of print("message")
12th Jul 2023, 4:58 PM
Asep Sujana
Asep Sujana - avatar
0
Brian changed 👍
12th Jul 2023, 8:10 PM
Ugulberto Sánchez
Ugulberto Sánchez - avatar