Common data types

Introduction to Python for Developers

Jasmin Ludolf

Senior Data Science Content Developer

Decimal data types

  • Integers: whole numbers

$$

  • Floats: numbers with decimals, e.g. 1.5
  • No quotation marks needed

$$

$$

new_ingredient_quantity = 1.5
Introduction to Python for Developers

Boolean data types

$$

  • Boolean: True or False
  • Great for storing yes/no information
  • Capitalized
  • No quotation marks

$$

is_in_stock = True
is_in_stock = False
Introduction to Python for Developers

The type function

  • Data types:
    • Strings
    • Integers
    • Floats
    • Booleans
type()
  • Tells us the data type
Introduction to Python for Developers

The type function

String

ingredient_name = "tomatoes"

print(type(ingredient_name))
<class 'str'>

Integer

ingredient_quantity = 2

print(type(ingredient_quantity))
<class 'int'>

Float

new_ingredient_quantity = 1.5

print(type(new_ingredient_quantity))
<class 'float'>

Boolean

is_in_stock = True

print(type(is_in_stock))
<class 'bool'>
Introduction to Python for Developers

Understanding data types

  • Understand what code is doing and why
  • Use type() to identify the type
  • Determine what operations we can perform

Person working with code on multiple screens

1 Image by wutzkoh
Introduction to Python for Developers

Operators

  • Symbols called operators to perform computations

Arithmetic operators:

  • + for addition
  • - for subtraction
  • * for multiplication
  • / for division

Numbers:

  • Work like regular math
    print(2 + 1.5)
    
3.5

Strings:

  • Only + and * work

"Hi" + "There" = "HiThere"

"Hi" * 3 = "HiHiHi"

Introduction to Python for Developers

Let's practice!

Introduction to Python for Developers

Preparing Video For Download...