0% found this document useful (0 votes)
3 views2 pages

Python Variable Assignment Guide

The document discusses variables in Python. It explains that setting a variable is done with the equals sign, like bandName = "The Beatles". Variables can then be printed or used in strings by concatenating them. The value of a variable can also be changed by reassigning it, so that batman could equal different actors like "Christian Bale" or later "Ben Affleck".

Uploaded by

Furqaan Ali
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Python Variable Assignment Guide

The document discusses variables in Python. It explains that setting a variable is done with the equals sign, like bandName = "The Beatles". Variables can then be printed or used in strings by concatenating them. The value of a variable can also be changed by reassigning it, so that batman could equal different actors like "Christian Bale" or later "Ben Affleck".

Uploaded by

Furqaan Ali
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python Revision Variables

Setting a variable is easy in Python. Whenever any word or number follows a = symbol, it is
regarded by Python as a variable.
For example, to set a variable called bandName to The Beatles we would do this:

bandName = “The Beatles”

Now we can concatenate the variable with strings. bandName = “The Beatles”

print(“The most successful band ever were “+ bandName)

Try these out on python and see if you can correct the errors:

bandName = "The beatles"     

print(bandName  " had 27 number 1 singles")

Correct code:

 bandName = "The beatles"      

print(“bandName”, are the most successful band ever with 15 number 1 albums)

Correct code:

We can change variables by reassigning the variable as something else. for example:
batman = “Adam West”

batman = “Michael Keaton”

batman = “George Clooney”

batman = “Christian Bale”

Every time the variable batman is reassigned as something else it forgets the old name.
There is no way to bring that back unless it is reassigned as a previous value.
Python Revision Variables

Use the Python interpreter to :

1. Assign Christian Bale as the variable for batman.

2. Print the variable for batman

3. Assign Ben Affleck

4. Print the variable for batman

Your code:

You might also like