Reaassigning Variables

An introduction to the use of Variables in Python

Reaassigning Variables

Let’s assign x first as an integer, and then reassign it as a string:

#Assign x to be an integer
x = 76
print(x)

#Reassign x to be a string
x = "Sammy"
print(x)
Show Output
76
Sammy

The example above shows that we can first assign the variable x and assign it with the value of an integer, and then reassign the variable x assigning it this time with the value of a string.

If we rewrote the program this way:

x = 76
x = "Sammy"
print(x)

We would only receive the second assigned value as the output since that was the most recent assignment:

Sammy

Reassigning variables can be useful in some cases, but you will want to be aware of the readability of your code and work to make your program as clear as possible.

Introduction

Write a program that stores a variable. It should then print the variable value before changing it.

Write a program that stores a variable. It should then print the variable value before changing it. Once changed the variable should be outputted again.

Write a program that stores a variable. It should then print the variable value before changing it. Once changed the variable should be outputted again.
The program should repeat this process for ALL data types using the same variable.

8.3 Reassigning Variables Task
Submit your completed task...
If you need to get in touch with Mr McG then this is the way….

What's your name?
image/svg+xml
Thank you [name], that's great.

Can I ask where you are from?
image/svg+xml
Hey [name], can I ask where you are from?
image/svg+xml
Hey [name], which class are you in?
image/svg+xml
OK [name], thanks for that.

I will need your email address so I can get back to you!!
image/svg+xml
Thanks [name], nearly there.

What can I help you with?
image/svg+xml

Thanks [name] from [whichclass][location], Mr McG will get your message…"
[message]"…and will get back to you ASAP via [email]. Catch you soon.

image/svg+xml
Thank you [name], Mr McG got your message.
Thanks [name], Mr McG will get back to you as soon as he can!!

Have a great day!!

K McGuinness - 2018

No personal data will be shared with any third party. The only data processed via this website is anonymous browsing data to best manage your user experience.