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:


Previous Post Next Post

Contact Form