📘 Python Crash Course – Chapter 2: Variables and Simple Data Types – Exercise 2-2 Solution
📝 Exercise 2-2
Task: Store a message in a variable, and print that message . Then change the value of your variable to a new message, and print the new message.
✅ Solution Code:
msg="this is old message"
print(msg)
msg="this is new message"
print(msg)
🧠 Code Explanation:
This Python code performs the following actions:
-
Store a message in a variable:
The variable
msg
is assigned the string"thsi os old message"
. This value is then printed using theprint()
function. -
Update the variable:
The value of
msg
is updated to"this is new message"
, and the updated value is printed.
🔍 Output:
this is old message
this is new message
📚 Related Exercises from Chapter 2:
- ➤ Exercise 2-1 | Simple Message Part 1
- ➤ Exercise 2-2 | Simple Messages Part 2
- ➤ Exercise 2-3 | Personal Message
- ➤ Exercise 2-4 | Name Cases
- ➤ Exercise 2-5 | Famous Quote
- ➤ Exercise 2-6 | Famous Quote 2
- ➤ Exercise 2-7 | Stripping Names
- ➤ Exercise 2-8 | Number Eight
- ➤ Exercise 2-9 | Favorite Number
- ➤ Exercise 2-10 | Adding Comments
- ➤ Exercise 2-11 | Zen of Python