Introduction to Python for Developers
George Boorman
Curriculum Manager, DataCamp
Syntax | Action | Example | Output |
---|---|---|---|
* |
Multiply | 4 * 10 |
40 |
+ |
Addition | 7 + 9 |
16 |
- |
Subtract | 23 - 4 |
19 |
/ |
Division | 27 / 3 |
9 |
** |
Power | 3 ** 2 |
9 |
% |
Modulo | 7 % 4 |
3 |
# Define total_spend total_spend = 3150.96
# Single quotes customer_name = 'George Boorman'
# Double quotes also work customer_name = "George Boorman"
current_top_album = "For All The Dogs"
# Convert to lowercase current_top_album = current_top_album.lower()
# List of prices prices = [10, 20, 30, 15, 25, 35]
# Get the value at the first index prices[0]
# Creating a dictionary
products_dict = {"AG32": 10, "HT91": 20,
"PL65": 30, "OS31": 15,
"KB07": 25, "TR48": 35}
# Create a prices set prices_set = {10, 20, 30, 15, 25, 35}
# Create a prices tuple prices_tuple = (10, 20, 30, 15, 25, 35)
Operator | Function |
---|---|
== |
Equal to |
!= |
Not equal to |
> |
More than |
>= |
More than or equal to |
< |
Less than |
<= |
Less than or equal to |
Keyword | Function | Use |
---|---|---|
if |
If condition is met | First in the workflow |
elif |
Else check if condition is met | After if |
else |
Else perform this action | After elif |
# Prices list prices = [9.99, 8.99, 35.25, 1.50, 5.75]
# Print each value in prices for price in prices:
print(price)
9.99
8.99
35.25
1.5
5.75
# Stock limit stock = 10 # Number of purchases num_purchases = 0
# While num_purchases < stock limit while num_purchases < stock:
# Increment num_purchases num_purchases += 1
# Print remaining stock print(stock - num_purchases)
Keyword | Function |
---|---|
and |
Evaluate if multiple conditions are true |
or |
Evaluate one or more conditions are true |
in |
Evaluate if a value is in a data structure |
not |
Evaluate if a value is not in a data structure |
list.append()
Additional built-in functions
zip()
enumerate()
Packages and modules
os
time
venv
pandas
requests
numpy
Introduction to Python for Developers