What is Python?
INTRODUCTION TO PYTHON FOR DEVELOPERS
Jasmin Ludolf
Senior Data Science Content Developer
What to expect
Learn all about Python
Think like a developer
Why is Python popular?
Write and run code
INTRODUCTION TO PYTHON FOR DEVELOPERS
Why learn Python?
General-purpose programming language
Used for apps, automation, websites, and
more
Facebook, Netflix, and Spotify
Clear, readable syntax
print("Hello!")
Large developer community
Free and open-source
Anyone can use it!
1 Image by Godfrey Atima, Pexels
INTRODUCTION TO PYTHON FOR DEVELOPERS
Build a recipe scaler
Python script: file with python code we run
Development practices:
Start small
Iterating
Testing
Documenting
INTRODUCTION TO PYTHON FOR DEVELOPERS
By the end of the course
Learn about:
Variables
Data types
Control flow
Code structure
INTRODUCTION TO PYTHON FOR DEVELOPERS
The print function
Built-in Python function
Displays code results
Used for testing
print()
INTRODUCTION TO PYTHON FOR DEVELOPERS
The print function
Built-in Python function
Displays code results
Used for testing
print("Hello, world!")
Hello, world!
print('Hello, world!')
Hello, world!
INTRODUCTION TO PYTHON FOR DEVELOPERS
Documenting with comments
Comments explain code
Start with # symbol
Appear in different color
Do not affect code
# This is a code comment
# The below is a print function
print("Hello, world!")
INTRODUCTION TO PYTHON FOR DEVELOPERS
Let's practice!
INTRODUCTION TO PYTHON FOR DEVELOPERS
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
1 Image by reginafosterphotos
INTRODUCTION TO PYTHON FOR DEVELOPERS
Data types
The kind of value
Number
Text
True/False
Python assigns data types automatically
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) print(ingredient_quantity)
Tomatoes 2
INTRODUCTION TO PYTHON FOR DEVELOPERS
Adjusting variables
print(ingredient_quantity)
ingredient_quantity = 1
print(ingredient_quantity)
INTRODUCTION TO PYTHON FOR DEVELOPERS
Let's practice!
INTRODUCTION TO PYTHON FOR DEVELOPERS
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
new_ingredient_quantity = 1.5
No quotation marks needed
INTRODUCTION TO PYTHON FOR DEVELOPERS
Boolean data types
Boolean: True or False is_in_stock = True
Great for storing yes/no information
Capitalized is_in_stock = False
No quotation marks
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 Integer
ingredient_name = "tomatoes" ingredient_quantity = 2
print(type(ingredient_name)) print(type(ingredient_quantity))
<class 'str'> <class 'int'>
Float Boolean
new_ingredient_quantity = 1.5 is_in_stock = True
print(type(new_ingredient_quantity)) print(type(is_in_stock))
<class 'float'> <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
1 Image by wutzkoh
INTRODUCTION TO PYTHON FOR DEVELOPERS
Operators
Symbols called operators to perform Numbers:
computations
Work like regular math
Arithmetic operators:
print(2 + 1.5)
+ for addition
3.5
- for subtraction
* for multiplication Strings:
/ for division
Only + and * work
"Hi" + "There" = "HiThere"
"Hi" * 3 = "HiHiHi"
INTRODUCTION TO PYTHON FOR DEVELOPERS
Let's practice!
INTRODUCTION TO PYTHON FOR DEVELOPERS