Defining Python Variables
   1 min read


There are several ways to define variables and assign values…

Define a variable using a string value
Example:

movie = 'Star Wars' #define variable & assign a string value.
print(movie) #outputs value.

Star Wars

Define a variable using a string concatenation expression
Example:

name = 'Nina' #define variable & assign a string value.
address = 'Hollyhock Cottage' #define variable & assign a string value.
contact = name + " resides at " + address #define & assign a string concatenation expression.
print(Contact) #outputs value.

Nina resides at Hollyhock Cottage

Define a variable using a mathematical expression
Example:

Number = 4 #define variable & assign an integer value.
Squared = Number * Number #define variable & assign a mathematical expression.
print(Squared) #outputs value.

16

What's on this Page