DEV Community

Cover image for Why Python? An Introduction for New Programmers
Emilio Ochieng
Emilio Ochieng

Posted on

Why Python? An Introduction for New Programmers

Python is a language people learn to code in — and for good reason. What starts as a simple print("Hello World") can grow into a skill used across nearly every industry, from e-commerce and logistics to firmware design and machine learning. This article walks through what makes Python approachable for beginners, and introduces the core building blocks you'll use in almost every Python program you write.

What Makes Python Easy to Learn?

A few things set Python apart as a beginner-friendly language:

  • Simple, readable syntax. Python code reads almost like plain English, which makes it easier to understand what a program is doing without memorizing a lot of symbols and rules.
  • A huge ecosystem of libraries. Whether you need to do arithmetic, deploy a machine learning model, or build a web application, there's very likely already a Python library for it.
  • A large, active community. Thousands of developers build and maintain these libraries, which means help, documentation, and examples are never far away.

Your First Line of Python

The most fundamental piece of code most programmers write first is the print() function:

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

The print() function sends data to the standard output device — usually your terminal or console — so you can see the result of your code.

Variables: Storing Data

A variable is a named storage location in your computer's memory that temporarily holds data while a program runs. Every variable has three key properties:

  1. The name (identifier) — the label you use to refer to the data in your code.
  2. The value — the actual data stored inside it.
  3. The data type — the category of data being stored.

Python has four basic data types you'll encounter constantly:

Type Description Example
Integer (int) A whole number age = 20
Float / Double A decimal number height = 1.93
String (str) Text greeting = "Hello World"
Boolean (bool) True or False under 18 = false

In each of these examples, the equal sign (=) is the assignment operator — it takes the value on the right and stores it in the variable name on the left.

Operators: Doing Something With Data

An operator is a symbol or keyword that tells the computer to perform a mathematical, relational, or logical operation on data. Python has four common categories:

Arithmetic Operators

Used for basic math: +, -, *, /, %

a = 100
b = 200
c = 300
d = 10
e = 3

total = a + b + c   # 600
diff = b - a         # 100
rem = d % e           # 1
div = c / d           # 100
Enter fullscreen mode Exit fullscreen mode

Assignment Operators

Used to assign or update the value stored in a variable: =, +=, -=, *=

score += count   # equivalent to: score = score + count
Enter fullscreen mode Exit fullscreen mode

Comparison / Relational Operators

Used to compare conditions: and, or, not

if age == 18 and id_present == True:
    print("You can vote")
Enter fullscreen mode Exit fullscreen mode

Loops: Repeating Actions Efficiently

A loop is a control flow structure that executes a block of code repeatedly as long as a condition is met. Loops matter because they:

  • Reduce redundancy — you don't have to manually repeat the same statement over and over.
  • Save time and space — they keep your codebase short, clean, and efficient.
  • Handle dynamic data — they let you process lists or user input of any size without rewriting your code.

The for Loop

Use a for loop when you know exactly how many times — or over exactly what items — you need to repeat an action:

items = ['Mercedes', 'BMW', 'Subaru', 'Mazda', 'Tesla']
for i in items:
    print(i)

# output
# Mercedes 
# BMW
# Subaru
# Mazda
# Tesla
Enter fullscreen mode Exit fullscreen mode

The while Loop

Use a while loop when the number of repetitions is unknown and depends on a condition remaining true:

while True:
    if i < 10:
        i += 1
    else:
        break
Enter fullscreen mode Exit fullscreen mode

Functions: Packaging Reusable Logic

A function is a self-contained, reusable block of code designed to perform one specific task. Instead of repeating the same instructions throughout your program, you package them inside a function, give it a meaningful name, and call it whenever you need it.

def sum(a, b):              # declaration & parameters
    result = a + b          # processing (body)
    return result            # return value

total = sum(100, 50)       # calling the function -> 150
Enter fullscreen mode Exit fullscreen mode

Breaking that down:

  • Name & parameters (inputs)a and b are placeholders for the data you pass into the function.
  • The body — the indented lines below the function name that carry out the actual logic.
  • The return value — the return statement sends the final result back to the main program and ends the function.
  • The function call — writing the function's name followed by parentheses, like sum(100, 200), tells Python to run that block of code and hand back the result.

Conclusion

Every program starts as an idea. That idea is often written down first as pseudocode, then translated into an actual programming language — and Python's simplicity is exactly why so many programmers choose it for that translation. It takes less code, and less time, to turn a thought into working software, which is what makes Python such a natural starting point for anyone learning to code.

Top comments (0)