Variables are instances of data saved to your system's memory. Variables are created to "store" data in human-readable text. Variables are nuclear (like string variables) and container (like dictionaries). Follow along to learn more about assigning data to variables.
In this section, you will learn how to:
Copy the following code on the left in your IDE to execute the process shown in the image on the right. Each code sample includes a description of the data type. The more complex data types will also include a representation of the appropriate syntax.
INTEGER ASSIGNMENT
Integers are numeric values presented as whole numbers
integer = 8
print (integer)
type (integer)
FLOAT ASSIGNMENT
Floats are numeric values presented as decimals
float1 = 2.3
print (float1)
type (float1)
STRING ASSIGNMENT
Syntax: variable = "text"
Strings are text values - characters, words, phrases, etc.
string = "Tulane University"
print (string)
type (string)
Boolean Assignment
boolean = True
print (boolean)
type (boolean)
boolean2 = False
print (boolean2)
type (boolean2)
LIST ASSIGNMENT
0 or more items stored as one object; items can be changed, added and removed
Syntax: variable = [item1, "item2",..., item n]
list1 = ["Green Wave", 1834, 30.5]
print (list1)
type (list1)
DICTIONARY ASSIGNMENT
0 or more items mapped to one another in a key-attribute structure
Syntax: variable = {key1:attribute1,
key2:attribute2,...,}
dictionary = {"name": "Kimberly",
"age": 22, "status": "undergraduate"}
print (dictionary)
type (dictionary)
SET ASSIGNMENT
0 or more items stored as one object, items in a set cannot be changed but new items can be added
Syntax: variable = {x,y,z}
set1 = {"New Orleans", "Louisiana", "NOLA"}
print (set1)
type (set1)
tuple1 = (("Let's", "Go", "Green Wave", 1834))
print (tuple1)
type (tuple1)
import pandas as pd
dataframe = pd.read_csv("filepath")
dataframe.head()
type(dataframe)