Python variables, strings, and integers

Introduction to Python for Developers

Jasmin Ludolf

Senior Data Science Content Developer

Understanding variables

  • Store and reuse information
  • Easy to read and update
  • Avoid typing things over and over

Jars in a kitchen cupboard

1 Image by reginafosterphotos
Introduction to Python for Developers

Data types

  • The kind of value
    • Number
    • Text
    • True/False
  • Python assigns data types automatically

Data types

Introduction to Python for Developers

String data types

  • Strings: text values
  • Can contain letters, numbers, and punctuation

$$

"Hello, world!"
"20-minute pasta recipe"
Introduction to Python for Developers

String data types

  • Strings: text values
  • Can contain letters, numbers, and punctuation
  • Use single or double quotes
  • Double quotes for words with apostrophes
"Chef's secret seasoning"
'Chef's secret seasoning'
Introduction to Python for Developers

String variable

$$

ingredient_name

$$

  • Use lowercase and underscores for spaces
Introduction to Python for Developers

String variable

$$

ingredient_name =
Introduction to Python for Developers

String variable

$$

ingredient_name = "Tomatoes"
Introduction to Python for Developers

Integer data types and variables

  • Integer: whole numbers
  • No quotation marks are needed

$$

ingredient_quantity = 2
Introduction to Python for Developers

Printing variables

print(ingredient_name)
Tomatoes
print(ingredient_quantity)
2
Introduction to Python for Developers

Adjusting variables

print(ingredient_quantity)
2

$$

ingredient_quantity = 1

print(ingredient_quantity)
1
Introduction to Python for Developers

Let's practice!

Introduction to Python for Developers

Preparing Video For Download...