DEV Community

Subash
Subash

Posted on

Day 1 of Learning Python: Introduction and Python Architecture

I've started learning Python, and I thought it would be a good idea to share what I learn every day. Writing things down should help me understand the concepts better, and maybe it will help other beginners too.

I missed the first class, so I'm catching up on the basics before moving forward.

What is Python?

Python is a high-level, general-purpose programming language. One thing I like about Python is that its syntax is easy to read compared to many other programming languages.

It is used in different fields, such as:

  • Web development
  • Artificial intelligence and machine learning
  • Data science
  • Automation
  • Software development

Let's start with a simple example.

print("Hello, World!")
Enter fullscreen mode Exit fullscreen mode

Output:

Hello, World!
Enter fullscreen mode Exit fullscreen mode

The print() function displays the message on the screen. Pretty simple, right?

How does Python work?

This was one of the interesting topics I wanted to understand.

When we write code, the computer cannot directly execute our Python source code as written. In the commonly used CPython implementation, the code goes through a process involving parsing, compilation into bytecode, and execution.

Here is a simplified view of the process:

Python source code → Parsing and compilation → Bytecode → Python Virtual Machine (PVM) → Output


Let's break it down:

1. Python source code

This is the code we write in a .py file.

2. Parsing and compilation

Python checks the syntax and compiles valid code into bytecode.

3. Bytecode

Bytecode is an intermediate form of instructions generated from our Python code.

4. Python Virtual Machine (PVM)

The PVM executes the bytecode instructions.

5. Output

Finally, we get the result of our program.

For example, when we run print("Hello, World!"), the output is displayed in the terminal.

This is a simplified explanation of how CPython works, but it helped me understand the basic execution flow.

What I learned today

  • What Python is and where it is used.
  • How to print output using print().
  • The basic process Python follows to execute a program.
  • What bytecode and the Python Virtual Machine do.

Top comments (0)