bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/Python

Python

Foundations

Start with Python syntax, variables, control flow, and the core pieces every later lesson depends on.

Lesson 1visual

Python Tutorial

Python Tutorial

2 min
Read lesson →
Lesson 2

Python Introduction

Python Introduction

2 min
Read lesson →
Lesson 3

Python Syntax

Execute Python Syntax As we learned in the previous page, Python syntax can be executed by writing directly in the Command Line: >>> print("Hello, World!") Hello, World! Or by creating a python file…

2 min
Read lesson →
Lesson 4

Python Statements

Statements A computer program is a list of "instructions" to be "executed" by a computer. In a programming language, these programming instructions are called statements. The following statement prin…

2 min
Read lesson →
Lesson 5

Python Comments

Comments can be used to explain Python code. Comments can be used to make the code more readable. Comments can be used to prevent execution when testing code. Creating a Comment Comments starts with…

2 min
Read lesson →
Lesson 6

Python Variables

Python Variables

2 min
Read lesson →
Lesson 7

Python - Variable Names

Variable Names A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume). Rules for Python variables: A variable name must start with a letter or the und…

2 min
Read lesson →
Lesson 8

Python Data Types

Built-in Data Types In programming, data type is an important concept. Variables can store data of different types, and different types can do different things. Python has the following data types bu…

2 min
Read lesson →
Lesson 9

Python Casting

Specify a Variable Type There may be times when you want to specify a type on to a variable. This can be done with casting. Python is an object-orientated language, and as such it uses classes to def…

2 min
Read lesson →
Lesson 10

Python Strings

Strings Strings in python are surrounded by either single quotation marks, or double quotation marks. 'hello' is the same as "hello". You can display a string literal with the print() function: Examp…

3 min
Read lesson →
Lesson 11

Python - String Methods

String Methods Python has a set of built-in methods that you can use on strings. Note: All string methods return new values. They do not change the original string. Method Description capitalize() Co…

3 min
Read lesson →
Lesson 12visual

Python Booleans

Booleans represent one of two values: True or False. Boolean Values In programming you often need to know if an expression is True or False. You can evaluate any expression in Python, and get one of…

2 min
Read lesson →
Lesson 13visual

Python Lists

mylist = ["apple", "banana", "cherry"] List Lists are used to store multiple items in a single variable. Lists are one of 4 built-in data types in Python used to store collections of data, the other…

3 min
Read lesson →
Lesson 14

Python - Copy Lists

Copy a List You cannot copy a list simply by typing list2 = list1, because: list2 will only be a to list1, and changes made in list1 will automatically also be made in list2. Use the copy() method Yo…

2 min
Read lesson →
Lesson 15

Python - List Methods

List Methods Python has a set of built-in methods that you can use on lists. Method Description append() Adds an element at the end of the list clear() Removes all the elements from the list copy() R…

2 min
Read lesson →
Lesson 16visual

Python Tuples

mytuple = ("apple", "banana", "cherry") Tuple Tuples are used to store multiple items in a single variable. Tuple is one of 4 built-in data types in Python used to store collections of data, the othe…

3 min
Read lesson →
Lesson 17

Python - Update Tuples

Tuples are unchangeable, meaning that you cannot change, add, or remove items once the tuple is created. But there are some workarounds. Change Tuple Values Once a tuple is created, you cannot change…

2 min
Read lesson →
Lesson 18

Python - Tuple Methods

Tuple Methods Python has two built-in methods that you can use on tuples. Method Description count() Returns the number of times a specified value occurs in a tuple index() Searches the tuple for a s…

2 min
Read lesson →
Lesson 19visual

Python Sets

myset = {"apple", "banana", "cherry"} Set Sets are used to store multiple items in a single variable. Set is one of 4 built-in data types in Python used to store collections of data, the other 3 are…

3 min
Read lesson →
Lesson 20

Python - Access Set Items

Access Items You cannot access items in a set by referring to an index or a key. But you can loop through the set items using a for loop, or ask if a specified value is present in a set, by using the…

2 min
Read lesson →
Lesson 21

Python - Join Sets

Join Sets There are several ways to join two or more sets in Python. The union() and update() methods joins all items from both sets. The intersection() method keeps ONLY the duplicates. The differen…

5 min
Read lesson →
Lesson 22

Python frozenset

Python frozenset frozenset is an immutable version of a set. Like sets, it contains unique, unordered, unchangeable elements. Unlike sets, elements cannot be added or removed from a frozenset. Creati…

2 min
Read lesson →
Lesson 23

Python - Set Methods

Set Methods Python has a set of built-in methods that you can use on sets. Method Shortcut Description add() Adds an element to the set clear() Removes all the elements from the set copy() Returns a…

2 min
Read lesson →
Lesson 24visual

Python Dictionaries

thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } Dictionary Dictionaries are used to store data values in key:value pairs. A dictionary is a collection which is ordered*, changeable a…

3 min
Read lesson →
Lesson 25visual

Python - Loop Dictionaries

Loop Through a Dictionary You can loop through a dictionary by using a for loop. When looping through a dictionary, the return value are the keys of the dictionary, but there are methods to return th…

2 min
Read lesson →
Lesson 26visual

Python - Copy Dictionaries

Copy a Dictionary You cannot copy a dictionary simply by typing dict2 = dict1, because: dict2 will only be a to dict1, and changes made in dict1 will automatically also be made in dict2. There are wa…

2 min
Read lesson →
Lesson 27visual

Python Dictionary Methods

Dictionary Methods Python has a set of built-in methods that you can use on dictionaries. Method Description clear() Removes all the elements from the dictionary copy() Returns a copy of the dictiona…

2 min
Read lesson →
Lesson 28

Python If Statement

Python Conditions and If statements Python supports the usual logical conditions from mathematics: Equals: a == b Not Equals: a != b Less than: a < b Less than or equal to: a <= b Greater than: a > b…

2 min
Read lesson →
Lesson 29

Python Elif Statement

The Elif Keyword The elif keyword is Python's way of saying "if the previous conditions were not true, then try this condition". The elif keyword allows you to check multiple expressions for True and…

2 min
Read lesson →
Lesson 30

Python Else Statement

The Else Keyword The else keyword catches anything which isn't caught by the preceding conditions. The else statement is executed when the if condition (and any elif conditions) evaluate to False. Ex…

2 min
Read lesson →
Lesson 31

Python Logical Operators

Python Logical Operators Logical operators are used to combine conditional statements. Python has three logical operators: and - Returns True if both statements are true or - Returns True if one of t…

2 min
Read lesson →
Lesson 32

Python Match

The match statement is used to perform different actions based on different conditions. The Python Match Statement Instead of writing many if..else statements, you can use the match statement. The ma…

2 min
Read lesson →
Lesson 33visual

Python For Loops

Python For Loops A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string). This is less like the for keyword in other programming languages,…

3 min
Read lesson →
Lesson 34

Python Functions

Python Functions A function is a block of code which only runs when it is called. A function can return data as a result. A function helps avoiding code repetition. Creating a Function In Python, a f…

2 min
Read lesson →
Lesson 35visual

Python Function Arguments

Arguments Information can be passed into functions as arguments. Arguments are specified after the function name, inside the parentheses. You can add as many arguments as you want, just separate them…

5 min
Read lesson →
Lesson 36visual

Python *args and **kwargs

*args and **kwargs By default, a function must be called with the correct number of arguments. However, sometimes you may not know how many arguments that will be passed into your function. *args and…

4 min
Read lesson →
Lesson 37

Python Scope

Scope A variable is only available from inside the region it is created. This is called scope. Local Scope A variable created inside a function belongs to the local scope of that function, and can on…

3 min
Read lesson →
Lesson 38

Python Decorators

Decorators let you add extra behavior to a function, without changing the function's code. A decorator is a function that takes another function as input and returns a new function. Basic Decorator D…

3 min
Read lesson →
Lesson 39

Python Lambda

Lambda Functions A lambda function is a small anonymous function. A lambda function can take any number of arguments, but can only have one expression. Syntax lambda arguments expression The expressi…

2 min
Read lesson →
Lesson 40visual

Python Recursion

Recursion Recursion is when a function calls itself. Recursion is a common mathematical and programming concept. It means that a function calls itself. This has the benefit of meaning that you can lo…

3 min
Read lesson →
Lesson 41

Python Generators

Generators Generators are functions that can pause and resume their execution. When a generator function is called, it returns a generator object, which is an iterator. The code inside the function i…

3 min
Read lesson →
Lesson 42

Python range

Python range The built-in range() function returns an immutable sequence of numbers, commonly used for looping a specific number of times. This set of numbers has its own data type called range. Note…

3 min
Read lesson →
Lesson 43

Python Arrays

Note: Python does not have built-in support for Arrays, but Python Lists can be used instead. Arrays Note: This page shows you how to use LISTS as ARRAYS, however, to work with arrays in Python you w…

3 min
Read lesson →
Lesson 44visual

Python Iterators

Python Iterators An iterator is an object that contains a countable number of values. An iterator is an object that can be iterated upon, meaning that you can traverse through all the values. Technic…

2 min
Read lesson →
Lesson 45visual

Python Modules

Python Modules

2 min
Read lesson →
Lesson 46visual

Python Math

Python has a set of built-in math functions, including an extensive math module, that allows you to perform mathematical tasks on numbers. Built-in Math Functions The min() and max() functions can be…

2 min
Read lesson →
Lesson 47visual

Python JSON

JSON is a syntax for storing and exchanging data. JSON is text, written with JavaScript object notation. JSON in Python Python has a built-in package called json, which can be used to work with JSON…

2 min
Read lesson →
Lesson 48

Python RegEx

A RegEx, or Regular Expression, is a sequence of characters that forms a search pattern. RegEx can be used to check if a string contains the specified search pattern. RegEx Module Python has a built-…

8 min
Read lesson →
Lesson 49

Python PIP

Python PIP

2 min
Read lesson →
Lesson 50visual

Python Try Except

The try block lets you test a block of code for errors. The except block lets you handle the error. The else block lets you execute code when there is no error. The finally block lets you execute cod…

2 min
Read lesson →
Lesson 51visual

Python String Formatting

F-String was introduced in Python 3.6, and is now the preferred way of formatting strings. Before Python 3.6 we had to use the format() method. F-Strings F-string allows you to format selected parts…

5 min
Read lesson →
Lesson 52

Python None

Python None None is a special constant in Python that represents the absence of a value. Its data type is NoneType, and None is the only instance of a NoneType object. NoneType Variables can be assig…

2 min
Read lesson →
Lesson 53

Python Virtual Environment

Python Virtual Environment

4 min
Read lesson →