Complete Python tutorial for Beginners 2023

What is Python?

John brown
11 min readApr 5, 2023

In this short guide you will find an explanation of Python — the very popular computer language — thanks to its variety of uses and ease of writing. In addition, you can find out how you too can learn the language preferred by companies, startups and programmers in the world.

How to start learning Python? Hello world and work environment

One of the biggest problems for those who have never learned programming is where to write the code and how to run it. In this guide you will find an explanation of how to write and run Python — from the simplest ways suitable for complete beginners to the development environments used by software professionals.

Python guide: variables, values ​​and print

Even in programming there are variables and they can receive any value that we place in them. You can place numbers, text (string), and other types that we will learn about in the guides in the Python learning series.

for loop — instead of repeating yourself run a loop

One of the advantages of using a computer is that it can perform the same operation an infinite number of times (almost) without complaining, without getting discouraged and without making mistakes. To perform the same operation, you can write the same code several times, but why bother? It is better to use a loop inside which we will run the same code as many times as we want. In this guide we will learn the topic of the for loop .

Python while loop

In the previous guide in the series for learning Python , we learned about for loops that in order to run it, you need to pre-define the range of values ​​within which the loop operates. In this guide we will learn about a while loop that runs until it meets a condition that causes it to stop or until it reaches break .

Python lists

A Python list list is a variable that can contain several items together. Another name for a list is an array. In this tutorial you will learn how to work with Python lists.

Python conditions using if, elif and else

Python’s conditions allow us to execute code only if it meets the conditions. In this guide, an initial introduction to the subject is necessary for every programmer.

Python tuples — immutable lists

In a previous tutorial we learned about lists which are the most popular data type when you want to store a collection of data. In this guide we will learn about tuples which are lists that cannot be changed and yet are very useful.

Dictionaries in the Python language

A dictionary allows you to hold several values ​​and retrieve information using keys.

Math in Python

Every programmer must have mathematical tools, and indeed Python includes a multitude of mathematical functions and libraries, and is even considered the leading language in the field of mathematics applications in programming. In this guide we will learn the basics of using mathematics in the Python language.

String operations in Python

The Python language includes a multitude of functions whose role is to handle texts. Illa functions are string functions. In Python there are several dozen string functions, and in this guide I will present several particularly useful functions and operations.

How to write functions in Python?

A function contains several commands that are grouped together under one name in such a way that it can be called from where it is needed, when it is needed. Functions are used everywhere in Python so it is very important to learn how to write them.

The four scopes of Python

One of the most important things for a programmer in any programming language is the field of variables ( scope ) which allows accessing variables according to the field in which they are defined. In Python, the LEGB rule is valid , which determines the order in which domains can be accessed. LEGB are acronyms for the names of the four Python domains.

Import files and modules

When we work on our programming task we will very quickly find that we need to use more than one file for three main reasons: the code we are writing becomes too long and difficult for us to manage, a team of programmers are working on the same project at the same time or we want to reduce the amount of effort by importing functions that they wrote other programmers, and packaged in modules. In this guide we will learn how to import our files and modules written by the Python community.

os module — Python ‘s relationship with the operating system

Python’s os module allows us to work with the operating system ( OS ). Run operating system commands and work with the file system, including navigating within the file system, and renaming files and folders.

Reading and writing files in Python

One of the most common tasks in Python programming is reading and writing files. Whether it’s writing to a simple text file, or copying an image, all these tasks require reading or writing files. In this guide you will learn the basic commands for reading and writing files in python.

Working with dates in Python

There are several libraries for working with times in Python. In this guide we will introduce the most important libraries.

Guide to regular expressions in Python

Regex regular expressions are used to find matches in text and are an important part of Python. In this guide you will learn the basics of regex that allows you to do a lot with a little code.

CSV tutorial in Python

In this guide we will learn how to use a CSV file similar to Excel and much more useful for programmers.

Working with Python in a mySQL database

In this guide, you will get an explanation of working with a mySQL database , because it is most commonly used in Python-based applications.

Handling exceptions in Python using the try and except blocks

Exception handling Exceptions is an accepted way to handle errors elegantly. For example, if our attempt to connect to the database fails, we can handle the error by referring to an alternate data source or at least provide an informative error message. This tutorial explains how to handle exceptions in Python.

Python in the real world

JSON and API consumption in Python

In the guide we will learn how to use JSON in Python. At the end of the guide I included a mini-project in which we will download the daily image from the API of the American space agency, NASA .

Finding broken links in a web page using Python and Selenium

Python’s selenium package is used to perform automatic tests of websites because it controls the browser and allows you to direct its behavior. For example, you can use selenium to test the behavior of a form in different scenarios and in different browsers and then run the script on automaton every day at the same time to make sure the form works. In the tutorial I will use selenium to find broken links on a page.

Web scraping using Python

Scraping web pages is a technology that allows us to copy the content of web pages and information sources on the web to our databases. In this tutorial we will learn how to scrape web pages using Python’s BeautifulSoup library and how to store the information we downloaded in the database and csv files on our computer/server.

Working with images in Python

One of the most common tasks in Python programming is working with images. In this guide, an explanation of the Pillow library that makes working with images, including opening, editing and using filters, very simple.

Why and how to work with a virtual environment in Python

The normal situation is that all the projects we write in Python depend on the same global packages we installed on our computer. The problem starts when we want to update the packages and then some projects stop working due to a backward compatibility problem. The solution is to use a virtual environment that allows you to manage the packages separately for each project. And the truth is that there is nothing easy about it because Python offers the venv module for managing a virtual environment as part of the standard library which means that it does not need to be installed.

Good to know

Python guide: list comprehensions

One of the treats offered by the Python language is list comprehension which works like loops on lists in a more compact and readable syntax.

What is a python generator ? and how to use it

Have you ever wanted to run a loop multiple times but the computer crashed in the middle. If this is the case or you are simply curious to know what a Python generator is then you have come to the right place. Python generators are useful if you need to run the same function multiple times. For example, performing an operation on a large number of records that are pulled from the database or when you want to perform a mathematical operation on a long series of numbers. Instead of a normal function running on all the data, a generator will allow the computer to work on one item at a time, which saves memory space and reduces the load on the computer.

Anonymous lambda functions in Python

One of the wonderful features of Python is its rich syntax. On the one hand, it makes it possible to reach the same result in a variety of ways, but it may also frustrate the new programmers who may very quickly come across an unfamiliar syntax when they are reading code that someone else wrote. So especially for those new programmers, I wrote a guide that explains about lambda functions, also called anonymous functions, unnamed functions, or lambda expressions.

map, filter, reduce guide

The functions map, filter, reduce are used in Python to perform the same operation on each of the items in the list without the need for a loop. In this guide you will learn about the functions and when you should use them.

args and kwargs in Python explained in plain language

After you’ve used Python’s libraries a bit, you must have come across two arguments that can be passed to functions named args and kwargs. In this guide we will explain them.

big-O expression for code efficiency

One of the most important issues that must concern every programmer is whether his code is efficient. This is important because inefficient code slows down processes and can cause the system to crash. The expression big-O describes the lengthening of the duration of the execution of a task in relation to the increase in the amount of information in which the process is fed. In this guide we will present some common ways to describe the extension of the duration of the code execution in relation to the amount of information using the expression big-O notation .

Binary search algorithm — from understanding to application

Binary search is a fast search algorithm. how fast 30 operations are enough to definitely find an item in a list of a billion items. Want to know more about the method and how to implement it in Python?

Algorithm Selection Sort

Selection sort algorithm Selection sort is almost the easiest algorithm to write and explain that is used to arrange items in ascending or descending order. The principle of operation of the algorithm is simple. Divide the array of items that need to be sorted into two: on one side the sorted items, and on the other side the items that still need to be sorted. For the arrangement we use a loop. Each time the loop runs it finds the smallest item, and moves it from the unordered list to the end of the ordered list.

The Quicksort algorithm and the division process

Quicksort is an extremely efficient algorithm for sorting items. Quicksort is based on the “divide and conquer “ approach that splits a large problem into sub-problems that are easier to solve. If the sub-problems are not easy enough to solve, they are also split. And repeat until you reach problems that are easy to solve. The algorithm solves the subproblems that are easy to solve, and merges the solutions back into the solution of the big problem.

FastAPI — Introduction to the best Python code library for building web applications

FastAPI is a fairly new Python framework for building web applications, yet it is considered by many to be the best of them. In the current guide we will build an API from scratch including: adding, reading, updating and deleting using the framework.

--

--