Aral Code

Python Tutorial

Python is one of the most popular programming languages in the world, and one of the easiest to start with. Its code reads almost like English, so you spend more time solving problems and less time fighting with symbols. It's used for data science, artificial intelligence, automation, websites, games and school research projects.

This free course has 23 short lessons. Every example shows the code and the output it prints, so you can follow along even on a phone. Each lesson ends with a Taglish summary and a quick quiz.

How to run the examples

Python runs on your computer, not inside a web page, so you'll need one of these:

  • On a computer: install Python from python.org, then use IDLE (it comes with Python) or VS Code. Lesson 2 shows how.
  • On a phone or a borrowed computer: use a free online Python editor, or an app such as Pydroid 3 on Android.

No previous coding experience is needed. If you've taken our JavaScript course, you'll find many ideas familiar.

What you'll be able to do

  • Write programs that ask questions, compute answers and print results
  • Make decisions with if and repeat work with loops
  • Organize data in lists and dictionaries
  • Write your own functions and use Python's built-in modules
  • Read and write files, and handle errors
  • Build a complete sari-sari store point-of-sale program

All lessons

Getting Started

  1. Introduction to PythonWhat Python is, why it's a great first programming language, what people build with it, and what a Python program looks like.
  2. Getting Started with Python — Install and Run Your First ProgramInstall Python on Windows or Mac, use IDLE and the Python shell, save and run a .py file, and options for phones and school computer labs.
  3. Python Syntax — Indentation and CommentsHow Python code is written — one statement per line, indentation instead of curly braces, case sensitivity, and writing comments with #.
  4. Python print() and input()Show output with print(), control separators and line endings, ask the user for input with input(), and convert typed text to numbers.

Variables & Data

  1. Python VariablesCreate variables in Python, follow naming rules, change values, assign several variables at once, and swap values in one line.
  2. Python Data TypesThe main Python data types — str, int, float, bool, None, list, tuple, dict and set — how to check them with type(), and how to convert between them.
  3. Python Numbers and MathArithmetic in Python — +, -, *, /, //, % and **, order of operations, round(), abs(), min(), max(), sum() and the math module.
  4. Python Strings and f-stringsCreate strings with quotes, use escape characters and multi-line strings, join and repeat text, get characters by index, slice strings, and format with f-strings.
  5. Python String MethodsClean and search text with upper, lower, title, strip, replace, find, count, startswith, split, join, isdigit and more.
  6. Python Comparison and Logical OperatorsCompare values with ==, !=, >, <, >= and <=, combine conditions with and, or and not, check membership with in, and chain comparisons like 80 <= grade <= 89.

Decisions & Loops

  1. Python if, elif and elseMake decisions in Python with if, elif and else. Build a DepEd grade descriptor, a voting eligibility checker and learn the one-line conditional expression.
  2. Python while LoopsRepeat code while a condition is true — counters, savings goals, input validation and menus — and control loops with break, continue and else.
  3. Python for Loops and range()Loop through lists, strings and ranges with for, use range() with start, stop and step, enumerate() for numbering, and nested loops for tables and patterns.

Collections

  1. Python ListsStore many values in a list — create, index and slice lists, change items, add and remove with append, insert, remove and pop, and check length and membership.
  2. Python List Methods, Sorting and List ComprehensionsSort lists with sort() and sorted(), reverse them, sort by a key, and create new lists in one line with list comprehensions.
  3. Python Tuples and SetsUse tuples for values that shouldn't change, unpack them into variables, and use sets to remove duplicates and compare groups with union and intersection.
  4. Python DictionariesStore labeled data in dictionaries with keys and values — read with [] and get(), add, change and delete entries, loop with items(), and build a price list and vote counter.

Functions & Modules

  1. Python FunctionsDefine reusable functions with def, pass arguments, return values (even several at once), use default and keyword arguments, and understand local and global scope.
  2. Python Modules — math, random, datetime and Your OwnUse Python's built-in modules with import — random for games and raffles, datetime for dates and ages, math, and create your own module file. Install extra packages with pip.
  3. Python File Handling — Read and Write Text FilesSave and load data with text files — open() modes, with statements, reading lines, writing and appending, and working with CSV files of grades.
  4. Python Errors and Exceptions — try, except, finallyRead Python tracebacks, know the common error types, and handle problems with try, except, else and finally. Raise your own errors with raise.

Going Further

  1. Python Classes and ObjectsObject-oriented programming in Python — define classes with __init__ and self, add methods, create objects, use __str__, and extend classes with inheritance.
  2. Python Final Project — Sari-Sari Store Point of SaleBuild a complete console point-of-sale program for a sari-sari store with a product list, cart, receipts, payment and change, input validation and a sales file.