Python Programming Series  ·  Article 1

Introduction to Python: A Complete Beginner's Guide

Welcome to your very first step into programming. This guide covers the fundamentals of Python: what it is, how you store and name data, the rules of the language, and then goes a level deeper into something most beginners never get told, which is what actually happens behind the scenes when you run code. By the end, you'll know how to write Python and understand what the computer is doing when it reads it.


What Is Python?

Python is an interpreted, high-level, general-purpose programming language. It's one of the most popular languages in the world today, and it has become the go-to language for data science. Here's what those three words actually mean.

High-level means it reads almost like English. You don't have to manage the tiny, fiddly details of how the computer's memory works; Python handles that for you.

Interpreted means Python runs your code line by line, rather than converting the whole program into machine code ahead of time. (We'll get into exactly what this means later, since it matters more than it sounds.)

General-purpose means it isn't locked to one job. You can build websites, analyze data, automate boring tasks, train AI models, or write games with it.

It's general-purpose, lightweight, and fast to write. Because it isn't specialized for a single task, you can use it for almost anything, and you'll write fewer lines than you would in most other languages.

It became the language of data science, almost by accident. Python wasn't designed for data science, but its simplicity plus a huge ecosystem of free, community-built tools (like NumPy, Pandas, Matplotlib, and SciPy) made it the natural home for working with data.

It has a flat learning curve. The syntax is clean and simple, which makes it approachable even for people who have never programmed before. Python is famous for being readable: you can often guess what a piece of code does just by looking at it.

It has a large, active community. This matters more than beginners realize. When you hit a problem (and you will), chances are someone has already solved it and posted the answer online. You're never really stuck alone.


Literals and Variables

These are the two most fundamental building blocks in any program, so it's worth understanding them clearly.

Literals: The Raw Data

A literal is a fixed value written directly into your code, a piece of raw information. There are many kinds, but the four you'll use most are:

python
10          # an integer literal
20.5        # a float literal
'Python'    # a string literal
True        # a boolean literal

A literal on its own is just a value sitting there. To actually use it, you usually store it somewhere, and that's where variables come in.

Variables: The Containers

A variable is a named container that holds a literal value. You give it a name, and you can use that name to retrieve or change the value later.

Storing a value into a variable is called assignment, and you do it with the equals sign (=):

python
num = 10
name = 'Shikhar'

Read the = as "gets" or "is assigned": "num gets the value 10." It is not the "equals" of mathematics; it's an instruction to store something.

The Rules for Naming Variables

Python is strict about variable names. Follow these rules:

python
num = 10          # valid
num1 = 10         # valid
num_2 = 20        # valid
_num3 = 30        # valid (starts with underscore)

4num = 40         # INVALID: starts with a digit
for = 50          # INVALID: 'for' is a keyword

For multi-word names, two common styles are used:

python
first_name = 'Shikhar'   # snake_case (preferred in Python)
firstName  = 'Virat'     # camelCase
FirstName  = 'Rohit'     # PascalCase

The most important naming advice: make your names descriptive. The computer doesn't care, but humans (including future-you) do.

python
a = 21       # what is 'a'? No idea.
age = 21     # instantly clear

The Basic Rules of Writing Python

Python has a few non-negotiable rules that trip up beginners. Knowing them up front saves a lot of frustration.

1. Indentation Matters

In most languages, indentation (the spaces at the start of a line) is just for looks. In Python, it's part of the language's grammar. Lines that belong together must be indented consistently. Starting a line with random spacing will cause an error:

python
print("Welcome to Python")
 print("Python is fun")     # ERROR: unexpected indentation

This is actually one of the reasons Python code looks so clean: the structure is forced to be visually organized.

2. No Punctuation at the End of Statements

Unlike some languages that end every line with a semicolon, Python wants lines clean. Don't add stray periods or commas at the end:

python
print("Welcome to Python").    # ERROR: trailing period breaks the syntax
print("Python is fun"),        # RUNS, but not the way you'd expect (see below)

That trailing comma is a sneaky one. It doesn't error, but it silently turns the statement into a one-item tuple. print("Python is fun"), still prints the text, but the whole expression evaluates to (None,), a tuple holding print's return value, which is always None. If you ever see a stray (None,) show up somewhere you didn't expect, a trailing comma like this is a common cause.

3. Python Is Case-Sensitive

print and Print are completely different things to Python. The built-in function is print (all lowercase). Capitalizing it breaks your code:

python
Print('Hello')    # ERROR: Python doesn't know 'Print'
print('Hello')    # correct

This applies to everything. age, Age, and AGE would be three separate variables.


Writing Comments

A comment is text in your code that Python completely ignores. It's there purely for humans, to explain what the code does and why. Good comments make a program far easier to read and maintain, both for others and for yourself months later.

Python has two ways to write comments.

Single-line comments start with a pound/hash sign (#):

python
# This declares a variable for the user's first name
first_name = 'Shikhar'

Multi-line (block) comments are wrapped in triple quotes (''' or """):

python
'''
This is a longer comment that
spans multiple lines, useful for
explaining a whole section of code.
'''

A good habit: write a short comment describing the purpose of each meaningful piece of code. You don't need to explain every line, but the intent behind a block should be clear.


Python Keywords

Keywords are reserved words that already have a special meaning to Python. Because Python needs them to understand your code, you cannot use them as variable names, function names, or any other identifier.

You can see the full list at any time:

python
import keyword
print(keyword.kwlist)
print("Total number of keywords:", len(keyword.kwlist))

Examples include if, else, for, while, def, class, import, return, True, False, and None. Almost all keywords are lowercase; the exceptions are True, False, and None, which are capitalized and must be written exactly that way.

You don't need to memorize them. You'll naturally learn them as you go, and Python will warn you if you accidentally try to use one as a name.


Identifiers

An identifier is simply the name you give to something in your program: a variable, a function, a class, and so on. (Variable names are the most common kind of identifier.)

The rules for identifiers are the same as the variable naming rules:

  1. They can contain letters (uppercase or lowercase), digits, and underscores.
  2. They cannot start with a digit (variable1 is fine, 1variable is not).
  3. They cannot be keywords.
  4. No special symbols (@, $, %, etc.) are allowed.
  5. They can be any length.

A few best practices worth repeating: Python is case-sensitive, so amount, AMOUNT, and aMouNT are three different identifiers. Choose meaningful names; num beats x, and compound_interest beats ci. Separate multiple words with underscores (snake_case) or capital letters (camelCase).


Three Important Things About Variables in Python

A few behaviors are especially worth understanding early.

1. Python Is Dynamically Typed

In Python, a variable can hold one type of value now and a completely different type later. You never have to declare what kind of data a variable will hold; Python figures it out on the fly:

python
num = 10        # num is currently an integer
num = 20        # still an integer, new value
num = 'Python'  # now it's a string, totally fine in Python!

This is not allowed in statically typed languages like C, C++, or Java, where a variable's type is fixed when you create it. (More on what "dynamically typed" really means later in this guide.)

2. Multiple Assignment in One Line

Python lets you assign several variables at once, which keeps code compact:

python
# Instead of three separate lines:
num1 = 10
num2 = 20
num3 = 30

# You can write:
num1, num2, num3 = 10, 20, 30

You can also give several variables the same value in one go:

python
val1 = val2 = val3 = 40

Here's a subtle detail worth sitting with. If you check the memory location of each of these variables using the id() function, they all point to the same place in memory:

python
id(val1)   # e.g. 140712834561234
id(val2)   # same number
id(val3)   # same number

Why? Because of how chained assignment works, not because of anything special about the number 40. When you write a = b = c = value, Python evaluates the right-hand side exactly once and then binds all three names to that single result. It doesn't matter what value is; the same thing happens with a string, a list, or any other object. That's why id() returns the same address for all three: they're not separate copies, they're three labels on the one object that got created.

python
val1 = val2 = val3 = 40
# One value '40' in memory, three labels pointing to it

3. Type Conversion

You can convert a value from one type to another using the type's name as a function. This is called type casting:

python
num1 = 10
type(num1)          # <class 'int'>

num1 = float(num1)  # convert to float
num1                # 10.0

val1 = 30.3
int(val1)           # 30  (note: the decimal is chopped off, not rounded)

str(num1)           # '10.0'  (now it's text)

But conversions only work when they make sense. You can't turn the word "Python" into a number:

python
int('Python')   # Raises ValueError: invalid literal for int()

This is logical: there's no number hiding inside the word "Python," so Python refuses.


Part Two  ·  What Actually Happens When You Run Code

This is the part most beginners never get explained, but understanding it will make you a far more confident programmer. Let's look under the hood.

How a Computer Actually Thinks

Here's the fundamental truth: a computer's processor (the CPU) only understands one language, machine code. This is pure binary, just 1s and 0s, representing electrical on/off signals. It looks nothing like Python. Something like num = 10 means absolutely nothing to the raw hardware.

So there's a gap. On one side, you have human-friendly Python. On the other, you have a machine that only speaks binary. Something has to bridge that gap, to translate your Python into instructions the CPU can actually execute.


How Python Reads Your Code

When you run a Python program, here's what happens, step by step, in plain English:

Step 1: Reading and checking (parsing). Python first reads through your code, top to bottom, and checks that the grammar makes sense. If you forgot a colon or misspelled something structurally, it stops right here and reports a syntax error before running anything. Think of this like proofreading a sentence before reading it aloud.

Step 2: Translating to bytecode. Python converts your readable code into an intermediate, compact form called bytecode. This isn't machine code yet; it's a halfway language that Python's engine understands. (You may have seen mysterious .pyc files or a __pycache__ folder appear. That's the saved bytecode, kept around so Python doesn't have to re-translate unchanged code every time.)

Step 3: Executing line by line. A program called the Python Virtual Machine (PVM) takes that bytecode and runs it, one instruction at a time, translating each piece into actual machine actions on the fly. This is the part that makes Python "interpreted": the running and the final translation happen together, live.

So the journey looks like this:

flow
Your Python code  →  Bytecode  →  Python Virtual Machine  →  CPU does the work
Your Python code (.py) parse Bytecode (.pyc) execute Python Virtual Machine (PVM) runs CPU does the work You write the first box. Python handles everything after it, automatically.
The journey from source code to CPU

You write the first box. Python handles everything after it, automatically, every time you hit "run."


What Happens in Memory (The Simple Version)

When your code creates data, that data has to physically live somewhere, in the computer's memory (RAM). Here's a beginner-friendly mental model of how Python handles this.

When you write:

python
num = 10

Two separate things happen: 1. Python creates an object in memory to hold the value 10. This object sits at a specific address, like a house on a street. 2. The name num becomes a label that points to that address.

Here's the insight that makes everything else click: in Python, a variable is not a box that contains a value. It's a label (or "tag") attached to a value living in memory.

This explains the earlier mystery. When you wrote val1 = val2 = val3 = 40, Python didn't make three copies of 40. It made one object holding 40 and stuck three labels on it. That's why id() returned the same address for all three: they were all pointing at the same house.

And when you do this:

python
num = 10        # 'num' label points to a 10 object
num = 'Python'  # the label is MOVED to point at a new 'Python' object

...the 10 doesn't get overwritten in place. Instead, a brand-new 'Python' object is created elsewhere, and the num label is simply moved over to point at it. The old 10, if nothing else points to it, eventually gets cleaned up automatically.

val1 = val2 = val3 = 40 val1 val2 val3 40 One object. Three labels pointing at it. num = 10 → num = 'Python' 10 no label points here: garbage collected num 'Python' label moves
Variables are labels, not boxes

Garbage Collection: Automatic Cleanup

That "cleaned up automatically" part has a name: garbage collection. Python keeps track of how many labels point to each object. When an object has no labels pointing to it anymore, it's unreachable, so Python automatically frees up that memory for reuse.

In lower-level languages like C, you have to manually claim and release memory, and forgetting to do so causes serious bugs. Python does this housekeeping for you behind the scenes, which is one of the big reasons it's so beginner-friendly. One less thing to worry about.


Interpreted vs Compiled Languages

This is one of the most useful distinctions to understand, and it's simpler than it sounds. Both approaches solve the same problem (translating human code into machine code), just at different times.

A compiled language (like C, C++, or Rust) translates your entire program into machine code before it runs, all at once. This translation step is called compilation, and it produces a standalone executable file. Running that file is then very fast, because all the translating is already done.

Analogy: Compiling is like translating an entire book from French to English, printing the finished English version, and handing it to the reader. The reader (the CPU) gets a complete, ready-to-read translation.

An interpreted language (like Python) translates and runs your code line by line, as it goes, every time you run it. There's no separate "build the whole thing first" step.

Analogy: Interpreting is like having a live human translator standing next to you, translating each sentence out loud the moment it's spoken. More flexible, but a bit slower, because translation happens during the conversation.

COMPILED (C, C++, Rust) translate entire program at once then run: fast, all translation is already done INTERPRETED (Python) line 1 line 2 line 3 line 4 line 5 line 6 line 7 ... Each line is translated and run before moving to the next, continuously, while the program executes. Same total work either way: the difference is WHEN the translation happens.
Same total translation work, different timing

Here's how they compare:

Compiled (C, C++) Interpreted (Python)
When translation happens Once, before running Continuously, while running
Speed of execution Very fast Slower
Ease of use / testing Slower to test (rebuild each time) Instant, just run it
Catches errors Many caught before running Often only when that line runs
Portability Tied to the system it was built for Runs anywhere Python is installed

The honest middle ground: Python is technically a blend. As you learned above, it first compiles your code to bytecode, then interprets that bytecode. But from a beginner's point of view, the experience is interpreted: you write code and run it instantly, with no separate build step.

The practical takeaway: Python trades some raw speed for a lot of convenience. For most tasks, that trade is well worth it.


Static vs Dynamically Typed Languages

We touched on this earlier; here's the full, simple picture.

The "type" of a variable means what kind of data it holds: a number, some text, a true/false value, and so on. The difference between static and dynamic typing is about when and whether you have to declare that type.

A statically typed language (like C, C++, or Java) requires you to declare a variable's type up front, and that type is locked in. A variable declared to hold a number can only ever hold a number.

java
// Java example
int age = 25;       // 'age' is declared as an integer, forever
age = "hello";      // ERROR: you can't put text in an integer variable

A dynamically typed language (like Python) figures out the type automatically based on whatever value you assign, and lets you change it freely:

python
age = 25         # Python sees a number, treats age as an int
age = "hello"    # now it's a string, perfectly fine

Here's the comparison:

Statically Typed (Java, C++) Dynamically Typed (Python)
Declare types? Yes, required No, automatic
Can a variable change type? No Yes
Catches type mistakes Before running Only when that line runs
Code length More verbose Shorter, faster to write
Best for Large, safety-critical systems Quick development, flexibility

The trade-off in one sentence: static typing catches more mistakes early but makes you write more, while dynamic typing is faster and more flexible but can let type-related bugs slip through until runtime. Python chooses flexibility, which is part of why it's so quick to learn.


Where Python Shines, and Where It Struggles

No language is perfect for everything. Understanding Python's strengths and weaknesses helps you know when to reach for it, and when something else might fit better.

Where Python Shines

Readability and beginner-friendliness. Python's clean syntax means you spend more time solving your actual problem and less time fighting the language. It's widely considered the best first language to learn.

Data science, machine learning, and AI. This is Python's biggest strength. The ecosystem of tools, NumPy, Pandas, scikit-learn, TensorFlow, PyTorch, is unmatched, and the large majority of AI research and development happens in Python1 (though performance-critical pieces are often written in C++, and languages like R and Julia hold their own in specific corners of data science).

Automation and scripting. Need to rename a thousand files, scrape a website, or automate a repetitive task? Python is well-suited for quick, practical scripts.

Web development (back-end). Frameworks like Django and Flask power many real websites and APIs.

Glue code and rapid prototyping. Python is well-suited for quickly stitching different systems together and for testing an idea fast before committing to a more complex build.

The community and libraries. For almost any task you can imagine, someone has probably already built a free Python library for it. This saves enormous amounts of time.

Where Python Struggles

Raw speed. Because it's interpreted and dynamically typed, Python is significantly slower than compiled languages like C++ or Rust for heavy number-crunching. (Clever workaround: speed-critical libraries like NumPy are actually written in C under the hood, so you get C-like speed with Python-like ease.)

Mobile app development. Python is rarely used to build phone apps. For that, languages like Swift (iOS) and Kotlin (Android) dominate.

Memory usage. Python's convenience comes at a cost: it generally uses more memory than lower-level languages, which can matter on devices with very limited resources.

True parallel processing. For most of Python's history, a design feature called the Global Interpreter Lock (GIL) has prevented standard Python from running multiple threads at full speed simultaneously across multiple CPU cores. This is genuinely changing: Python 3.13 introduced an experimental mode that lets you disable the GIL, and Python 3.14 made that "free-threaded" mode officially supported.2 It's still opt-in rather than the default, and a lot of the ecosystem (including some C extensions) is still catching up, so for now it's worth knowing the limitation exists rather than relying on it being solved. You don't need to understand the details yet, just that this is an active area of change in Python.

Very high-performance or real-time systems. For things like operating systems, game engines, or systems where every microsecond counts, compiled languages are usually the better choice.

Put together, Python is a flexible, beginner-friendly language that's fast to write even when it isn't the fastest to run. For most of what people actually want to do, especially data, automation, and AI, its strengths far outweigh its weaknesses.


Putting It All Together

Let's tie the whole journey together with a single, simple line of code and trace what happens:

python
age = 25
print(age)
  1. You write these two human-readable lines.
  2. Python parses them, checking the grammar is valid.
  3. It translates them into bytecode.
  4. In memory, an object holding 25 is created, and the label age is attached to it.
  5. The Python Virtual Machine executes the bytecode line by line, first the assignment, then the print.
  6. The CPU carries out the actual work, and 25 appears on your screen.
  7. When the program ends, Python's garbage collector cleans up the memory automatically.

All of that, from two tiny lines, happens in a fraction of a second, and now you understand every step.


Quick Reference Summary

Concept Key Idea
Python Interpreted, high-level, general-purpose, beginner-friendly
Literal A raw fixed value: 10, 20.5, 'Python', True
Variable A named label pointing to a value in memory
Assignment (=) Stores a value into a variable ("gets," not math equals)
Keywords Reserved words you can't use as names (if, for, True...)
Identifier Any name you create for a variable, function, or class
Indentation Part of Python's grammar, not optional
Case sensitivity print ≠ Print; age ≠ Age
Comments # for one line, '''...''' for blocks; ignored by Python
Dynamic typing Variables can change type freely
Type conversion int(), float(), str(), only when it makes sense
id() Shows an object's memory address
Bytecode The intermediate form Python translates your code into
PVM The Python Virtual Machine that runs the bytecode
Garbage collection Automatic cleanup of unused memory
Compiled vs Interpreted Translate-all-first vs translate-as-you-go
Static vs Dynamic typing Fixed types declared up front vs flexible automatic types

You now have the what of Python's basics, plus the why and the how underneath them. When you teach a new learner, start with literals and variables, let them write a few lines, and then reveal the behind-the-scenes story: variables as labels, code becoming bytecode, the virtual machine doing the work. That moment when someone understands what's really happening inside the machine is when programming stops feeling like magic and starts feeling like a tool they can command.

Where this leaves you: you now have the what of Python's basics, plus the why and the how underneath them. That's usually the point where programming stops feeling like magic and starts feeling like a tool you can actually direct.
Notes
  1. Estimates vary by survey and year (roughly 58–70% of AI/ML practitioners report Python as their primary language as of 2026, per Stack Overflow and industry surveys), so "large majority" is used here rather than a single precise figure that would go stale quickly.
  2. Python 3.13 (October 2024) introduced free-threading as an experimental, opt-in build (PEP 703). Python 3.14 (October 2025) promoted it to officially supported status (PEP 779), though it remains opt-in rather than the default build, and third-party C extensions are still being updated for compatibility.