Python Programming for Beginners

A Hands‑On Crash Course with Step‑By‑Step Projects to Learn Python Fast and Build Real‑World Skills

Start coding in Python today—no prior experience required. Python Programming for Beginners: The Fundamentals is a complete, beginner-friendly course designed to take you from “Hello, world” to writing real programs with confidence—without overwhelming theory or assumed experience.

هذا الكتاب متوفر أيضاً باللغة العربية 📘

Book cover: Python Programming for Beginners, authored by Ahmad Al Khatib

Get the free Python book (100+ pages), with exercises and solutions included

Submit to receive the free Python book, with downloadable full code file. Perfect for your first wins!

We’ll email you the download links. No spam, ever.

A quick look at the table of contents

  1. Introduction
  2. Download and install the book’s prerequisites
  3. Chapter 1: An Exploratory Tour in Python
  4. Chapter 2: Numbers and Strings and Some Basic Operations
  5. Chapter 3: Lists and Loops
  6. Bonus: Downloadable resources
  7. Chapter 4: The if Conditional Statement
  8. Chapter 5: Dictionary, Tuple, and Set
  9. Chapter 6: The Conditional Loop, While Loop
  10. Chapter 7: Functions
  11. Chapter 8: The Class, OOP
  12. Chapter 9: File Management, Importing, and Some Basics

Read the introduction

Introduction

Since the dawn of the twenty-first century, we have witnessed an immense digital surge, ushering in a new technological era that complements the digital revolution which began in the mid-twentieth century with the first appearance of the computer. This new era is characterized by advanced, intelligent electronic applications that invade our lives, expand into every aspect of them, and take root—parallel to a qualitative leap in the field of smart mobile devices, now accessible to everyone and spreading among the peoples of the earth like wildfire.

This new technological era—the era of smart devices and applications—has left a profound and far-reaching impact on our modern lifestyle, making it easier on multiple levels. For instance, who among us does not use the WhatsApp application and even rely on it for many daily tasks? Whether for chatting with family and friends or for work and communication with clients… The same question applies to many other applications that have permeated our lives and claimed a significant share of them—from Google and its ease of access to information, to Facebook and Twitter and the social media revolution, to ChatGPT and Gemini and the surge of artificial intelligence… and many more applications whose role and influence have grown so immense that they have become an urgent daily necessity and a way of life that is hard to abandon.

The deep impact this era has left on various aspects of our lives is a clear indication of the tremendous importance of the sciences that this great technology has brought us—namely, computing sciences. In this book, we will explore one essential and fascinating branch of these sciences: programming.

To further illustrate the significance of programming and its pivotal role in this age, let us consider this example and imagine what might happen if—for some reason—all software systems in a given country were to fail:

Such a grim scenario would likely lead to the following: government offices grinding to a halt, citizens unable to complete transactions, internet service collapsing, wireless communications failing, banks, factories, companies, airplanes, and high-speed trains ceasing to operate, and so on… In short, it would be a catastrophic scenario akin to life coming to a standstill.

In the digital age we live in, most operations depend fundamentally and critically on computing technology and programming. Consequently, programming has become a vital, indispensable necessity of our time.

This immense importance of programming has led to an enormous surge in demand for it, placing programming-related jobs at the forefront of the labor market. Learning this skill has become a golden opportunity to secure employment—not just any employment, but highly rewarding positions with generous pay, whether as permanent roles in companies or as freelance work that can be done from home.

So, if you are among those looking to seize this great opportunity to boost your income by learning an enjoyable and not overly demanding skill, and you are wondering where and how to begin, this book is your gateway to achieving that—through learning the wonderful programming language Python.

Who This Book Is For

This book is for anyone who wants to learn programming with Python from the ground up—students, self-learners, and professionals building new skills or preparing for a career change. No prior programming experience is required, and you don’t need advanced math—basic computer skills, curiosity, and a bit of practice are enough. If you’re completely new to coding (or you’ve tried before and felt stuck), this book is designed to guide you toward writing your own programs with confidence.

What is Python? And why did I choose it in this book as an entry point into the world of programming?

Python is a widely renowned programming language developed by the brilliant Dutch programmer Guido Van Rossum, who named it “Python” after the famous comedy series Monty Python’s Flying Circus. The first version of this language was released in 1991, and it has grown tremendously to become one of the most popular and widely used programming languages in the world.

Why Python?

With hundreds of programming languages available, the first question that may come to mind for someone deciding to learn programming is: “Which programming language should I choose?” My answer is: “Choose Python without hesitation,” for many reasons, including:

• Ease of learning combined with powerful performance: Python is a smooth, easy-to-learn language, ideal for beginners, while also being extremely powerful and highly efficient for use in complex and advanced fields. For example, it is used in advanced research at NASA.

• High demand and lucrative returns: Python is among the most sought-after and widely used programming languages. It is employed by major global companies such as Google, Facebook, Instagram, YouTube, Amazon, Uber… Moreover, it ranks among the highest-paying programming languages. For instance, according to Glassdoor, the average annual salary for a Python programmer in the United States ranges from $80,000 to $120,000.

• Compatibility with different operating systems and versatility of use: Python is compatible with most well-known operating systems, such as iOS, Android, Linux, macOS, Windows, and others. This powerful language also boasts a wide range of applications—from automation to statistical and data sciences, to artificial intelligence, to web development, to game development, and more… along with many other reasons that make Python our language of choice.

I now place in your hands this comprehensive book covering most of Python’s fundamentals, written in a simple, fluid style that is easy for both young and old to understand. I have structured it in a semi-interactive manner, including code samples alongside their execution results, and enriched it with detailed, abundant explanations—similar to student notes—so that readers can learn independently without needing additional lessons or training courses. I have organized its topics in a flexible, systematic progression1, dividing it into two parts:

Part One: Fundamentals—distributed across nine essential chapters, accompanied by practice exercises.

1 The reader may notice a similarity between the sequence of this book’s chapter titles and those of Python Crash Course. That book had a significant impact on me and served as my entry point into the world of Python many years ago.

Part Two: Practical Applications—consisting of five projects for hands-on experience in building programs and applications, which include, in sequence:

Figure A: Creating a video game from scratch that includes numerous features.
Figure A: Creating a video game from scratch that includes numerous features.
Figure B: Creating an interactive live chart program to analyze currency prices, receiving data via API.
Figure B: Creating an interactive live chart program to analyze currency prices, receiving data via API.
Figure C: Creating an automation program that opens a specific website and automatically performs predefined tasks.
Figure C: Creating an automation program that opens a specific website and automatically performs predefined tasks.
Figure D: Creating a web application that generates text and draws images using artificial intelligence via API.
Figure D: Creating a web application that generates text and draws images using artificial intelligence via API.
Figure E: Creating a dynamic personal portfolio and blogging platform that manages data through a customized administrative backend.
Figure E: Creating a dynamic personal portfolio and blogging platform that manages data through a customized administrative backend.

And I have equipped this comprehensive book, which covers most of the fundamentals of Python, with a detailed Table of Contents that can serve as a dictionary for this powerful, elegant, and easy-to-learn language.

Ahmed Al-Khatib

Downloading and Installing the Book’s Requirements

Downloading and Installing the Book’s Requirements

In this short setup chapter, we’ll install Python and PyCharm so you can write and run code exactly as we do throughout the book.

1 – Downloading and Installing Python

Figure 5: Downloading Python
Figure 5: Downloading Python

You can download the latest version of Python to your computer from the official website via the following link: https://www.python.org/downloads/ Then click the Download button shown in the image (Figure 5) under the heading Download the latest version.

Once the download is complete, open the installer file.

» Note: If you’re installing Python on Windows, select “Add Python to PATH” before continuing with the installation, usually shown on the first screen. This helps you run Python from the Command Prompt later.

Then follow the on-screen steps to finish installing Python on your device.

2 – Downloading and Installing PyCharm

Figure 6: Downloading PyCharm
Figure 6: Downloading PyCharm

You can download the free PyCharm Community edition from the official JetBrains website via the link: https://www.jetbrains.com/pycharm/download/ Then, choose your operating system, and select the version that matches your computer’s specifications before clicking the Download button shown in the image (Figure 6) under the Community heading. Once the download is complete, open the file to install the program on your device.

2.1 – An Exploratory Tour of PyCharm

2.1.i – What is PyCharm?

PyCharm is a program used to write, debug, and run Python code. It belongs to a category of programs known as IDE, which stands for Integrated Development Environment.

PyCharm offers a wide range of tools and features, such as intelligent code recognition, automatic code completion, and others. It is highly efficient while remaining easy to use. One of its standout advantages is the ability to set up virtual environments with a single click, without the need to configure them manually through code. Additionally, PyCharm is available in a free edition called PyCharm Community, which is the version we will use throughout this book to write and execute Python code.

2.1.ii – The PyCharm Interface

» Note: A new version of PyCharm may be released after I complete this book, which could cause slight differences between the screenshots included below and the interface of the newer version. However, these differences do not affect the fundamentals we are covering in this explanation.

Figure 7: Creating a Project in PyCharm
Figure 7: Creating a Project in PyCharm

After launching PyCharm, the screen shown in (Figure 7) appears. From this interface, you can create a new project by clicking the New Project button indicated by ➀, or open an existing project—if available—such as the one marked by ➁.

Figure 8: Setting the Project Environment in PyCharm
Figure 8: Setting the Project Environment in PyCharm

After clicking the New Project button to create a new project, the screen shown in (Figure 8) appears. From this screen, you can:

  • Choose a name for the project you want to create by replacing the blue-highlighted text indicated by ➀ with your desired name.
  • Select a virtual environment for the project by the field marked as ➁ (in this book, we will always use a virtual environment by selecting Virtualenv or venv).
  • Specify the Python version to be used in the project through the field indicated by ➂ (we will use the latest version of Python that we downloaded earlier).

Finally, click the Create button marked as ➃ to create the new project.

What is the Virtual Environment?

This is just for your information—you do not need to fully understand it at this point. Some readers may have just decided to start learning programming through this book and might be completely unfamiliar with programming terms and tools. So, we will explain the role of Virtualenv using a simple analogy rather than a purely technical approach:

Imagine you have a smartphone with WhatsApp installed, and you want to install another app. However, for some reason, this new app cannot run on the same phone alongside WhatsApp. To solve this problem, you might think about uninstalling WhatsApp—but you need it constantly. Or you might consider buying a new phone just to install the second app—but that seems difficult and expensive!

This is where the idea of a virtual environment comes in. It allows you to create two isolated environments on the same device, so you can install each app in its isolated environment and run them on the same device as if each were installed on a separate phone. Similarly, in programming, we use virtual enervironments to avoid conflicts between different project packages on the same machine.

Figure 9: PyCharm Interface
Figure 9: PyCharm Interface

» Note: If PyCharm opens with its new interface and you want to switch back to the classic interface used in this book, you can do so by clicking the ☰ button at the top-left corner of the program window, then selecting Settings from the menu. Next, go to Appearance & Behavior, click New UI, and uncheck the box next to Enable new UI to disable it. Finally, click OK, then Restart to reopen PyCharm with the old interface. You can return to the new interface later by repeating the same steps and re-enabling Enable new UI.

After clicking the Create button to create the project, the main PyCharm interface appears as shown in (Figure 9). This interface can be divided into three main sections:

  • Section ➀: Used to manage the project files.
  • Section ➁: Where we write the Python code.
  • Section ➂: A multi-purpose display area.

This interface also includes a button to run the code, which we indicated in ➃

2.2 – Downloading and Installing the Required Packages/Libraries

Figure 10: Installing Packages in PyCharm
Figure 10: Installing Packages in PyCharm

PyCharm also stands out for its ease of downloading and installing libraries, which we will explain in more detail later in this book.

To install a specific library, click the Python Packages button at the bottom of the PyCharm interface, as shown in (Figure 10) at point ➀. Then, enter the name of the library you want to download in the field indicated by ➁, and finally click the Install Package button marked as ➂ to download and install that library.

Below is a list of the libraries required for the second practical section of this book. You can install them now one by one, or postpone this step until after completing the first section:

  • pygame
  • matplotlib
  • pandas
  • pygal
  • pygal_maps_world
  • streamlit
  • pillow
  • lxml

» Note: You can practice the first part of the book on smartphones and tablets using apps such as Replit on iPad and iPhone devices, or Dcoder on Android devices. However, for the second part of the book, you need a computer and libraries installed.

Read Chapter One Sample

Chapter 1 Sample: An Exploratory Tour in Python

» Note 1: To learn from this book effectively and understand the exercises more easily, prepare PyCharm or a similar IDE so you can practice writing every code example presented and test running them yourself.

1 – The print() Function

In the introduction of this book, we mentioned Python’s distinctive simplicity. In Python, we can display—meaning print—any content on the screen, whether text, numbers, or symbol, simply by using one of the commands known as functions. The function we use for this purpose is print(), where we place the content we want to display inside its parentheses.

Here’s a simple example: If we enter the following code in the code editor of an IDE such as PyCharm or any similar program:

print("I wrote my first code!")

If we then run this code using the button we previously pointed out at the top of the PyCharm interface, this causes the content entered between the parentheses of the print() command to be displayed on the screen, and the result appears as follows:

I wrote my first code!

The meaning of this code is that we are instructing Python to display a specific piece of content on the screen using the print() command. The content we want to display is placed between the parentheses of this command, and we enclose it in double quotes " " to indicate to Python that it is textual content. In Python, text is identified by enclosing it in double quotes, and such text is referred to as a string.

» Note 2: We can also use single quotes ' ' instead of double quotes to define string content in Python. And this usage becomes mandatory in certain cases to avoid errors. Below are some examples:

Example 1

Using single quotation marks in the following code:

print('I started programming!')

serves the same role as double quotation marks. It tells Python that the content placed between these quotation marks is a string. In other words, it defines the text enclosed within them as textual content. Running this code displays the following output on the screen:

I started programming!

Example 2

However, if the text content you want to use already contains double quotes in its original form—such as the following sentence:

He says: "Hello mom!"

In this case, it becomes necessary to use single quotes instead of double quotes to define this string, in order to avoid errors, as shown in the example attached in the image below.

Figure 1.1: Using the single quotes to define a string, in order to avoid errors
Figure 1.1: Using the single quotes to define a string, in order to avoid errors

Example 3

The same applies when the text content you want to use already contains a single quote (apostrophe) in its original wording. In this case, you do not use single quotes to define the string; instead, you use double quotes to avoid errors, as shown in the example attached in the image below.

Figure 1.2: Using double quotes to define a string, in order to avoid errors
Figure 1.2: Using double quotes to define a string, in order to avoid errors

2 – Variables and Values

Storing information in programs for various purposes is one of the most fundamental principles of programming. In Python, we can store specific pieces of information under designated names, so that we can access any of these pieces of information later by referring to the name in which it was stored.

The stored piece of information is technically called a value, and the name under which this information is stored is called a variable. Here’s an example:

country_name = "Egypt"

In the line of code above, we stored the value "Egypt" in the variable country_name. If we then print this variable using the print() function, as shown in the following line of code:

print(country_name)

This outputs the value stored in the variable country_name, not the variable name itself. The result of running this code is:

Egypt

» Note 3: If we print the name of the previous variable "country_name" enclosed in quotation marks, as shown in the following line of code, Python interprets it as a string not as a variable. Running this code therefore prints the name itself:

print('country_name')
country_name
Figure 1.3: Variables and Values
Figure 1.3: Variables and Values

» Note 4: If a variable name consists of two or more words, do not separate them with spaces (for example, country name). Instead, use underscore (country_name) to avoid errors:

country name = "USA"
error

In addition to the previously mentioned rules for naming variables, numbers can also be used in a variable name (for example, country1_name_1). However, never start a Python variable name with a number, as this causes error:

1country_name = "KSA"
error

» Note 5: If the same variable name is repeatedly used across multiple lines of code to store different pieces of information, then printing the content of this variable in such a case displays the content of the most recent variable assigned that name. Below is an example:

given_name = 'George Washington'
given_name = 'Martin Luther King Jr.'
print(given_name)
Martin Luther King Jr.

►► Quick Review: Up to this point, we have learned how to define strings in Python by enclosing them in double quotes or single quotes. We have also learned how to display text on the screen using the print() function, and how to store a piece of information (a value) in a name (a variable).

3 – The Methods: .title(), .lower(), and .upper()

In Python, there is another set of commands known as methods. For now, you do not need to focus on these names—such as method and function—since we will cover them later in detail (and from this point onward, we will indicate the results of running the code by highlighting them).

drink = "water"
print(drink)
water
print(drink.upper())
WATER

In line 1 of this (code) example, we stored the value 'water' in the variable drink. Then, in line 2, we printed the content of this variable using the print() function. After running this code, as shown in the output of line 2—and as expected—it printed the value stored in this variable in its original form.

As for line 3, printing the contents of the variable drink using the print() function, combined with adding the .upper() method—which converts the characters of a string to uppercase—resulted in printing the contents of this variable in uppercase letters: WATER.

These commands, whose meanings are clear, are among the features of Python, which makes it easier for programmers to remember the functions of Python commands based on their meanings, as print() and .upper().

We can also convert the letters of strings to lowercase by using the .lower() method. And it isn’t required to use these commands inside the parentheses of the print() function as we did in the previous example; they can be used in different contexts, as we will do in the next example:

name_1 = "EMMA"
name_2 = name_1.lower()
print(name_2)
emma

Another common style used for writing proper names, book titles, and similar items consists of capitalizing the first letter of \each word while writing the remaining letters in lowercase. For example: John Kennedy.

In Python, we can convert text into this format by using the .title() method. Here’s an example:

presidential_candidates = "donald trump, joe biden, kamala harris"
print(presidential_candidates.title())
Donald Trump, Joe Biden, Kamala Harris

►► Reminder: If you encounter any difficulties as beginners starting out with this book, I encourage you to reach out to me on social media to share your questions, or contact me through my website:

@alkhatib_ahmad1

https://ahmad-khatib.com/en/https://ahmad-khatib.com/en/

Chapter One Exercise

The exercise for this introductory chapter is very simple. Try to unleash your imagination and write a piece of code that is at least ten lines long. You might design it so that, when executed, it prints your name and the names of your family members or friends in different letter cases. Make sure to use the following commands and symbols in your code:

= " " ' ' print() .lower() .upper() .title(),

Why This Book

Here’s the difference: you don’t just read about Python. You learn each concept, see it working, and then practice it through guided mini-programs and exercises with solutions—so the understanding truly sticks when you code on your own.

  • Beginner-friendly and easy to follow: Clear explanations using a Code + Result approach, written specifically for absolute beginners—no confusing jargon.
  • No prior programming or math background required: Start from zero with step-by-step guidance throughout the book.
  • Learn clean, professional Python the right way: Build strong coding habits from day one using industry-proven best practices.
  • Real-world examples you can actually use: Practical examples and exercises—not abstract theory.
  • Learning that stays enjoyable: Explanations, examples, and exercises designed to keep you engaged through hands-on practice.
  • More than a book—it’s a career foundation: Develop skills you can grow into real projects, jobs, and long-term opportunities.

What you can do with confidence after finishing this book

  • Set up Python properly and understand PyCharm IDE workflow, virtual environments, and why they matter (so projects stay clean and organized).
  • Write clean Python using variables, numbers, and strings—including essential text methods and formatting (f-strings, split, replace, and more).
  • Use lists effectively: add/remove/sort, slicing, copying, list comprehension.
  • Control program logic with if/elif/else, comparisons, and logical conditions.
  • Organize real data using dictionaries, tuples, and sets.
  • Build interactive programs with input() and while loops (including validation, flags, break/continue).
  • Create reusable code with functions (default values, return values, *args, **kwargs).
  • Understand classes and core object-oriented programming (OOP) concepts.
  • Read and write files, import modules, and organize larger projects efficiently.

Projects you’ll build

  • A simple game (from scratch) with multiple features.
  • A live chart app pulling price data from an API.
  • A browser automation script that performs tasks for you.
  • An AI text and image demo via API calls.
  • A personal portfolio/blog with a custom admin backend.

Frequently asked questions

Is this book right for total beginners?

Yes. It’s written for absolute beginners with clear examples and guided practice.

How long until I build my first working program?

Within the first chapter you’ll run real code; the mini projects can be completed in about an hour.

Do I need a specific operating system?

No. The book covers setup and runs on Windows, macOS, and Linux.

What’s included with the free pack?

A 2‑page Python cheat sheet and five mini projects with starter code and solutions.

Author photo: Ahmad Al Khatib

About the author

Ahmad Al Khatib is a Lebanese technologist and programmer passionate about artificial intelligence, dedicating his expertise to making modern technology accessible to everyone—especially beginners. He holds specialized certifications in multiple tech fields and authors books that simplify programming and digital development concepts in a clear, engaging style. In his latest work, “Learn Python in Less Than a Week,” Ahmad lays out a practical, methodical roadmap for mastering Python efficiently. Outside writing and coding, he follows Middle East startup trends, blogs about tech and politics, and stays active in his online community. For exclusive lessons, updates on new releases, and deep insights into the world of technology, you’re invited to join his growing network.

Ready to enhance your skills and advance your career with Python?

This book guides you step by step to learn the most in-demand programming language efficiently, with clear explanations, practical examples, and hands-on exercises. Build real projects, strengthen your coding foundation, and open doors to new opportunities in tech.

Get your copy now