Exercise 2-2 Solution – Python Crash Course Chapter 2: Variables and Simple Data Types

 

πŸ“˜ 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:

  1. Store a message in a variable:

    The variable msg is assigned the string "thsi os old message". This value is then printed using the print() function.

  2. 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:


“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