Programs · Program 5-2
Q.Program 5-2: Write a program to display values of variables in Python.
Uttarakhand UbseTextbookSubjective· 2mImportance★★★★★est
8% · 4/49 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →print(variable) displays the value a variable currently holds; combining a label string and the variable with a comma gives readable output.
The idea. A variable is a name that refers to a value stored in memory. To see that value we hand the variable to print() — Python looks up the current value and displays it. This works for every type: strings, integers, floats, and so on, because print() converts each item to text before displaying it.
Program
# prog5-2.py
# Program to display values of variables
message = "Keep smiling!"
userNo = 101
print(message)
print("User number is", userNo)
Expected output
Keep smiling!
User number is 101
Key lines
message = "Keep smiling!"binds the namemessageto a string value;userNo = 101bindsuserNoto an integer. Note that no type declaration is needed — Python infers the type from the assigned value.print(message)prints the value of the variable, not the name. …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.