Category: New Python tutorial

python tutorials and learn python

Created with Sketch.

Python Type Hints

Python Type Hints Summary: in this tutorial, you’ll learn about the python type hints and how to use the mypy tool to check types statically. Introduction to Python type hints Some programming languages have static typing, such as C/C++. It means that you need to declare types of variables, parameters, and return values of a…
Read more

Python Partial Functions

Python Partial Functions Summary: In this tutorial, you’ll learn about Python partial functions and how to define partial functions using the partial function from the functools module. Introduction to Python partial functions The following example defines a function that multiplies two arguments: def multiply(a, b): return a*b Code language: Python (python) Sometimes, you just want…
Read more

Python **kwargs

Python **kwargs Summary: in this tutorial, you’ll learn about the Python **kwargs parameters. Introduction to the Python **kwargs parameters In Python, a function can have a parameter preceded by two stars (**). For example: **kwwargs The **kwargs is called a keyword parameter. When a function has the **kwargs parameter, it can accept a variable number…
Read more

Python *args

Python *args Summary: in this tutorial, you’ll learn about the Python *args parameters and how to use them for defining variadic functions. Tuple unpacking The following unpacks a tuple into two variables: x, y = 10, 20   Python assigns 10 to x and 20 to y. It’s similar to passing two arguments to a…
Read more

Python Unpacking Tuple

Python Unpacking Tuple Summary: in this tutorial, you’ll learn how to unpack tuples in Python. Reviewing Python tuples Python defines a tuple using commas (,), not parentheses (). For example, the following defines a tuple with two elements: 1,2 Code language: Python (python) Python uses the parentheses to make the tuple clearer: (1, 2) Code…
Read more

Python do…while Loop Statement Emulation

Python do…while Loop Statement Emulation Summary: in this tutorial, you’ll learn how to emulate the do…while loop statement in Python Introduction to the do…while loop statement If you have come from other programming languages such as JavaScript, Java, or C#, you’re already familiar with the do…while loop statement. Unlike the while loop, the do…while loop…
Read more

Python while else

Python while else Summary: in this tutorial, you’ll learn about the Python while else statement and how to use it effectively. Introduction to Python while else statement In Python, the while statement may have an optional else clause: while condition: # code block to run else: # else clause code block Code language: PHP (php)…
Read more

Python for else

Python for else Summary: in this tutorial, you’ll learn about the Python for else statement and how to use it effectively. Introduction to the Python for else statement In Python, the for statement can have an optional else clause, which you may not be familiar with especially if you’re coming from other languages such as…
Read more

Python try…except…else

Python try…except…else Summary: in this tutorial, you’ll learn how to use the Python try…except…else statement. Introduction to the Python try…except…else statement The try statement has an optional else clause with the following syntax: try: # code that may cause errors except: # code that handle exceptions else: # code that executes when no exception occurs…
Read more

Python try…except…finally

Python try…except…finally Summary: in this tutorial, you’ll learn about the Python try…except…finally statement. Introduction to Python try…catch…finally statement The try…except statement allows you to catch one or more exceptions in the try clause and handle each of them in the except clauses. The try…except statement also has an optional clause called finally: try: # code…
Read more