FREE COURSE | BEGINNER

Python Fundamentals

Build readable programs for everyday tasks, automation and problem-solving.

Learning objectives

Write Python 3 programs using variables, conditions, loops, collections and functions; validate data and build a grade analyzer.

01. Introduction to Python

Python is a general-purpose language used for automation, web development and data analysis. Python 3 executes source code through an interpreter. Indentation groups statements into blocks.

Python source code

Expected output (original example)

Hello, Python!

Editing code does not change this reference output. Run locally to test changes.

Try it yourself

Change the greeting.

02. Installation and Python Syntax

Install Python 3 from python.org. Check your installation with python --version (or python3 --version). Save the example as hello.py and run python hello.py (or python3 hello.py). Comments begin with #.

Python source code

Expected output (original example)

Learn. Code. Build. Innovate.

Editing code does not change this reference output. Run locally to test changes.

Try it yourself

Save and run the program in a terminal.

03. Variables, Data Types and Input/Output

Variables refer to values. Common types are int, float, str and bool. input() returns a string; int() converts valid integer text. Use print() for output.

Python source code

Expected output (original example)

Name: Age: Hello, Ana! Next year: 21

Sample inputs: Ana, 20. Editing code does not change this reference output. Run locally to test changes.

Try it yourself

Try another name and age. Invalid integer input raises ValueError.

04. Operators and Expressions

Use +, -, *, / for arithmetic, // for floor division, % for remainder and ** for powers. Comparisons return Boolean values. Parentheses control grouping.

Python source code

Expected output (original example)

3.5 3 1
49
True

Editing code does not change this reference output. Run locally to test changes.

Try it yourself

Predict the output when a is 10.

05. Conditional Statements

if, elif and else select a branch. Use == for equality, not =. Indent each branch consistently, preferably four spaces.

Python source code

Expected output (original example)

Passed

Editing code does not change this reference output. Run locally to test changes.

Try it yourself

Test scores of 90, 75 and 74.

06. Loops and Iteration

for iterates over an iterable. range(start, stop) excludes stop. while repeats while its condition is true; update the condition to avoid an infinite loop.

Python source code

Expected output (original example)

1
2
3
2
1

Editing code does not change this reference output. Run locally to test changes.

Try it yourself

Change the range to print 1 through 5.

07. Collections and Functions

Lists are ordered and mutable; tuples are immutable sequences; dictionaries map keys to values; sets store unique elements. def defines a function and return sends a result to its caller.

Python source code

Expected output (original example)

Ana
85.0
[1, 2]

Editing code does not change this reference output. Run locally to test changes.

Try it yourself

Add another score. Keep the list nonempty.

08. Interactive Python Practice Lab

Trace a for loop that accumulates a running total. The simulator below illustrates the same logic without executing arbitrary Python code.

Python source code

Expected output (original example)

15

Editing code does not change this reference output. Run locally to test changes.

Loop simulator

Sum: 15

JavaScript simulation, not a Python interpreter.

Try it yourself

Predict the sum for 10 before running the simulation.

09. Mini Project: Student Grade Analyzer

Combine functions, lists, validation and conditions. This example uses fictional grades. Validate that scores are between 0 and 100 before calculating the average.

Python source code

Expected output (original example)

Average: 85.00 | Passed
Invalid scores

Editing code does not change this reference output. Run locally to test changes.

Try it yourself

Try an empty list and a list with an average below 75.

Knowledge Check

Official Python tutorial · Back to Courses