π 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
πTrending Topics
π Connect With Us:
“In the world of code, Python is the language of simplicity, where logic meets creativity, and every line brings us closer to our goals.”— Only Python
π Follow Us And Stay Updated For Daily Updates
Comments
Post a Comment