Skip to Main Content

Introduction to Python

This guide was designed to supplement the INTRODUCTION TO PYTHON virtual workshop. If you have concerns or suggestions for this guide, feel free to reach out to scholarlyengagement@tulane.edu.

What are variables?

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:

  • Differentiate between common object types - numbers (floats and integers), strings, lists, dictionaries, tuples
  • Assign objects to nuclear and container variables

Variable Assignment Code

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)


TUPLE ASSIGNMENT

0 or more items stored as one object, items in a tuple cannot be changed and no new items can be added

Syntax: variable = ((x,y,z))                                                                          

tuple1 = (("Let's", "Go", "Green Wave", 1834)) 
print (tuple1)
type (tuple1)

 


DATA FRAME ASSIGNMENT(Pandas Library)

structured data presented as rows and columns (similar to a spreadsheet or csv file).

import pandas as pd
dataframe = pd.read_csv("filepath")
dataframe.head()                                                                                    

 

 

 

 

 

 

 

 

 

 

 

type(dataframe)

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.