Python Zero to Heros

Online Absolute Beginner Python Tutorials 

Every Sunday 1pm (UK time/ BST)

Get this slide deck: bit.ly/PythonBasics1

Integers (int)

Whole numbers

1, -10, 10000000000000000, 0

Can perform arithmatic calculations (+, -, *, /)

Decimal numbers (float)

1.5, 3.14, 0.7, -999.99, 0.0

Can also perform arithmatic calculations (+, -, *, /)

Arithmatic Calculations

Try the following:
1+15
2*40
9-22
10/2
2**3
5//2

Strings (str)

a series of characters

"Hello", "My name is Cheuk", "https://cheuk.dev", ""

Can perform concatination: "Hello " + "World"

Have build in methods (e.g. "Hello World".split())
Can get a characters form a string: "Hello"[1]
Can get a section of a string: "Hello"[:4]

Formatted String

(Python >= 3.6)
f"I have {1+2} apples", f"My car is {color}"
 

Variables

Like a coffee mug that I used to buy coffee
I can buy americano, latte or mocha
And the same cup can be used

Try this:
x = "car"
x = 4
x = 1+5

x = "Hello " + "World"

x = "year " + 2020
x = "Cheuk
y = f"My name is {x}"

Build-in Functions

Pre-defined operations
https://docs.python.org/3/library/functions.html

print(), abs(), int(), float(), str(), type(), len(), exit()

Try this:

age = 18
print(f"I am {age} years old")

abs(-10)

type(20)

type("20")

type(int("20"))
len("Hello world")

Let's write some programs

 

1. given a name and a pronoun and a favourite thing, print a self introduction (lazy_self_intro.py)
 

2. given an amount of money, an annual interest rate and number of years, print how much I have to pay back for the loan (loan_calculator.py)

Homework 📝

 

1. Given the name of the student, the class they are in and their score of a certain subject, print a one-liner report for that student. (student_report.py)

2. Given the amount of the mortgage, the annual interest rate and the amount that I am paying back each month, calculate after how many years I will completely pay back my mortage. (mortgage_calculator.py)

Next week:
List & Dictionary

Sunday 1pm (UK time/ BST)

There are also Mid Meet Py every Wednesday 1pm