Introduction to Python

Session Overview

  • Launching Python
  • Versions
  • Python as a Calculator
  • Variable Assignment
  • Beginning data structures

Let’s Play!

Launching Python

  • Run python on the command line.

  • What version are you running?

  • What is your prompt?

Calculations

  • Try addition, subtraction, division, and multiplication

What is the difference between 2.0 + 1.0 and 2+1?


What about 10/2?

Variable Assignment

Variables are stored using the = in python.


a = 2
b = 3
c = 1.0

a + b + c

Variable Assignment

a = "Hello"
b = "World"

a 
b 

a + b


a + b + c

Beginning Data Structures

What are Data Types?

Beginning Data Structures

What are Data Types?


How data are stored in memory:

  • Integers: int
  • Floats: float, complex
  • Strings (Text): str
  • Boolean: bool

Beginning Data Structures

a = "Hello"
type(a)

b = 2
type(b)

c = 2 + 1j
type(c)

d = True
e = False
type(d)
type(e)

Beginning Data Structures

a = 10
b = 2
c = a/b

type(a)
type(b)
type(c)

Beginning Data Structures

a = 2.0

b = str(a)
b

type(a)
type(b)


a = "2.0"

b = int(a)
b = float(a)

type(a)
type(b)

c = int(b)
type(c)

Beginning Data Structures

Make 24 from dividing two large numbers.


When done:

quit()