Lesson 1 · Full-Length Courses
Python for Beginners: A Practical Introduction
This lesson introduces core Python programming concepts using a Jupyter Notebook inside VS Code. You will learn variables, user input, type conversion,…
- CourseFull-Length Courses
- Lesson1 of 7
- Video35 min
- FormatJupyter notebook · 26 code cells
What you'll learn
Data
No separate download needed — the notebook creates or downloads everything it uses.
📓 Full notebook
Download .ipynbPython for Beginners: A Practical Introduction#
- This lesson introduces core Python programming concepts using a Jupyter Notebook inside VS Code.
- You will learn variables, user input, type conversion, strings, arithmetic and comparison operators, if statements, loops, lists, and tuples.
- By the end, you will be able to write small, working Python programs and understand the errors Python shows you along the way.
What Can You Do With Python?#
- Python is a multi-purpose programming language used across many fields.
- It is the leading language for machine learning and data science projects.
- With the Django framework, Python powers major websites such as YouTube, Instagram, Spotify, Dropbox, and Pinterest.
- Python is also widely used for automation, saving time by handling repetitive tasks.
Installing Python#
- Head over to python.org and go to Downloads to get the latest version of Python for your operating system.
- Run the installer. On Windows, make sure to check the box that says Add python.exe to PATH before clicking Install, since this lets your terminal and VS Code find Python.
- On macOS, simply run the installer package and follow the prompts.
Setting Up VS Code and Your First Notebook#
- Install Visual Studio Code from code.visualstudio.com.
- Inside VS Code, open the Extensions view and install the Python extension and the Jupyter extension, both published by Microsoft.
- Open the Command Palette with Control plus Shift plus P, type Create: New Jupyter Notebook, and press Enter.
- In the top right corner of the notebook, click Select Kernel and choose your installed Python interpreter.
print('Hello World')
age = 20
print(age)
age = 30
print(age)
price = 19.95
first_name = 'Alex'
is_online = True
print(price, first_name, is_online)
is_online = false
Practice Exercise: Hospital Check-In#
- Imagine you are writing a program for a hospital checking in a new patient named John Smith, who is 20 years old.
- Declare variables to store the patient's name, age, and whether they are a new patient, then print them out.
name = input('What is your name? ')
print('Hello ' + name)
birth_year = input('Enter your birth year: ')
age = 2024 - birth_year
print(age)
birth_year = input('Enter your birth year: ')
age = 2024 - int(birth_year)
print(age)
Practice Exercise: Basic Calculator#
- Write a program that asks the user to enter two numbers, one at a time, allowing whole numbers or decimals.
- Print the sum of the two numbers, labeled clearly, such as sum is 30.
first = float(input('First number: '))
second = float(input('Second number: '))
sum = first + second
print('Sum is ' + str(sum))
course = 'Python for Beginners'
print(course.upper())
print(course.lower())
print(course.find('for'))
print(course.replace('Beginners', 'Everyone'))
print('Python' in course)
print(10 + 3)
print(10 - 3)
print(10 * 3)
print(10 / 3)
print(10 // 3)
print(10 % 3)
print(10 ** 3)
x = 10
x = x + 3
print(x)
x += 3
print(x)
x = 10 + 3 * 2
print(x)
y = (10 + 3) * 2
print(y)
print(3 > 2)
print(3 >= 3)
print(3 < 2)
print(3 <= 2)
print(3 == 2)
print(3 != 2)
price = 25
print(price > 10 and price < 30)
price = 5
print(price > 10 or price < 30)
print(not (price > 10))
temperature = 35
if temperature > 30:
print('It is a hot day')
print('Drink plenty of water')
elif temperature > 20:
print('It is a nice day')
elif temperature > 10:
print('It is a bit cold')
else:
print('It is a cold day')
print('Done')
Practice Exercise: Weight Converter#
- Write a program that asks for a weight, then asks whether that weight is in kilograms or pounds, entering k or l.
- Convert and print the weight in the other unit. Pounds to kilograms multiplies by 0.45; kilograms to pounds divides by 0.45.
weight = input('Weight: ')
unit = input('(K)ilograms or (L)bs: ')
if unit.upper() == 'K':
converted = float(weight) / 0.45
print('Weight in pounds is ' + str(converted))
else:
converted = float(weight) * 0.45
print('Weight in kilograms is ' + str(converted))
i = 1
while i <= 5:
print(i)
i = i + 1
i = 1
while i <= 10:
print(i * '*')
i = i + 1
Lists#
- Numbers, strings, and Booleans are Python's primitive, or basic, data types.
- Python also has complex data types built from these, and lists are one of the most common.
- We use a list whenever we want to represent a collection of objects, such as a list of names or numbers.
names = ['John', 'Bob', 'Alex', 'Sam', 'Mary']
print(names)
print(names[0])
print(names[-1])
print(names[-2])
names[0] = 'Jon'
print(names)
names = ['John', 'Bob', 'Alex', 'Sam', 'Mary']
print(names[0:3])
print(names)
numbers = [1, 2, 3, 4, 5]
numbers.append(6)
print(numbers)
numbers.insert(0, -1)
print(numbers)
numbers.remove(3)
print(numbers)
print(1 in numbers)
print(10 in numbers)
print(len(numbers))
numbers = [1, 2, 3, 4, 5]
for item in numbers:
print(item)
for number in range(5):
print(number)
for number in range(5, 10):
print(number)
for number in range(5, 10, 2):
print(number)
numbers = (1, 2, 2, 3)
print(numbers.count(2))
print(numbers.index(3))
numbers = (1, 2, 3)
numbers[0] = 10
Recap#
- We covered variables, user input, and type conversion between strings, integers, floats, and Booleans.
- We covered string methods, arithmetic, comparison, and logical operators, plus operator precedence.
- We covered if, elif, and else for decision making, and while loops for repeating code.
- We covered lists and tuples: creating them, indexing and slicing, adding and removing items, and iterating with for loops and range.
- Practicing each exercise yourself in a Jupyter Notebook in VS Code is the best way to make these concepts stick.
Found this useful?
All lessons, notebooks and datasets here are free. If they helped you, a coffee keeps new lessons coming.



