Values and Variables

Introduction

In this short exercise you will create a series of values and assign them to variables to solidify your knowledge of values, variables, operators, and types.

Solution Description

For each of the comments below, write the specified Python code. You may do this in the Python interactive shell or by creating a Python script that you run from the command line or import into an interactive Python shell (which runs the code). You could copy the comments below and paste them into a text file with a .py extension to get started with the script approach.

# Assign the value 3 to the variable a. What is the type of a?
# How do you know the value of a?



# Assign the value 4 to the variable b.



# Assign the result of dividing a by b to the variable d using the / operator.
# What is the type of d?




# Assign the result of dividing a by b to the variable e using the integer floor division operator, //.
# What is the type of e?




# Assign the remainder of the integer division a // b to the variable f.
# This operation is known as `mod` or "modulus" and is represented with % in Python.



# Assign the string value "foo" to the variable x.



# Assign the string value "fighter" to the variable y.



# Assign the value of x + y to the variable z. What is the value of z?



# Add 1 to z with the + operator. What happens?