Beginner Roadmap to Python: Part 1

Krupa SawantKrupa Sawant
6 min read

In this guide, I’m going to skip the fluff and dive straight into Python syntax.
It’s perfect if you already have some programming background — maybe in C, Java, or JavaScript — and just want to see how Python works differently.

Let’s start with a small example:

cash = 0
print(cash)

# adding 4 to count
cash = cash + 4

if cash > 0:
    print("I am getting rich")

multiply_cash = "Cash " * cash
print(multiply_cash)

Output:

0
I am getting rich
Cash Cash Cash Cash

Here’s what’s happening:

  1. We first assign 0 to the variable cash.

  2. Then we increment it by 4.

  3. Since cash > 0, the if condition runs, printing "I am getting rich".

  4. Finally, "Cash " is multiplied by cash, resulting in "Cash Cash Cash Cash".


Key differences you might notice if you’ve used other languages like C or Java:

  1. No need to declare variable types — Python figures it out automatically.

  2. print() is a built-in function, and comments start with the # symbol.

  3. if statements end with a colon (:) and the indented block defines the scope (no curly braces).

  4. Strings can be enclosed in single or double quotes.

  5. Operators can behave differently — for example, multiplication can also be used with strings.


Before We Jump Into Data Types

Before exploring Python’s data types, it’s important to understand that Python is dynamically typed. This means you don’t need to tell Python what kind of data a variable will hold — it decides at runtime. You can even reassign a variable from a number to a string without errors.

Data Types & Operations in Python

Python works with different types of data, and you can perform various operations on them.

1. Common Data Types

TypeExampleDescription
int10, -3Whole numbers
float3.14, -0.5Numbers with decimal points
str"hello"Text data (strings)
boolTrue, FalseLogical values

You can check a variable’s type with type():

x = 42
print(type(x))  # <class 'int'>

2. Arithmetic Operators

OperatorNameDescription
a + bAdditionAdds two numbers
a - bSubtractionDifference between a and b
a * bMultiplicationProduct of a and b
a / bTrue DivisionQuotient of a and b (returns a float)
a // bFloor DivisionQuotient without the fractional part
a % bModulusRemainder after division of a by b
a ** bExponenta raised to the power of b
-aNegationNegates the value of a

True division vs Floor division:

print(5 / 2)   # 2.5 (True division)
print(5 // 2)  # 2   (Floor division)

3. Order of Operations (PEMDAS)

Python follows Parentheses → Exponents → Multiplication/Division → Addition/Subtraction:

print((3 + 5) * 5 - 5)  # 35
# Parentheses first → multiplication → subtraction

4. Useful Built-in Functions

print(min(1, 2, 3))   # 1  → minimum value
print(abs(-32))       # 32 → absolute value

# Type conversion
print(float(10))      # 10.0
print(int(3.33))      # 3
print(int('807') + 1) # 808

💡 int() and float() can be used to convert between numbers and numeric strings.

Functions in Python

In Python, functions are blocks of reusable code that perform specific tasks.
You’ve already used built-in functions like print() to display output and abs() to get the absolute value of a number.

If you ever want to learn how a function works, use the help() function:

help(print)

This shows you how to use print(), the parameters it accepts, and what each does.
For example:

  • print() can take multiple values.

  • You can change how it separates them using sep.

  • You can change what it prints at the end using end.

Using help() is a quick way to understand any function without searching online.


1.Common Pitfall with help()

When using help(), always pass the function name without parentheses:

help(round)      # ✅ Correct — shows info about the function
help(round(3.6)) # ❌ Incorrect — shows info about the result (int), not the function

Why?

  • round → refers to the function itself.

  • round(3.6) → calls the function and returns a value (4).

  • So help(round(3.6)) is really help(4), which shows documentation for integers.


2.Defining Your Own Functions

Example — calculating the area of a square:

def area_of_square(side_length):
    """Calculate the area of a square given the side length."""
    return side_length * side_length

print(area_of_square(5))   # 25
print(area_of_square(10))  # 100

How it works:

  1. def starts the function definition.

  2. area_of_square is the function name.

  3. side_length is the parameter.

  4. Inside the function, we multiply the side length by itself.

  5. return sends the result back.


3.Default Arguments

You can set default values for parameters:

def apply_discount(price, discount=10):
    return price - (price * discount / 100)

print(apply_discount(100))     # 90.0 (default 10% discount)
print(apply_discount(100, 20)) # 80.0 (20% discount)

If you don’t provide a discount, it defaults to 10%.


4.Higher-Order Functions

Some functions take other functions as inputs. Example:

def mod_5(x):
    """Return remainder when dividing x by 5."""
    return x % 5

print(max(100, 51, 14))               # 100
print(max(100, 51, 14, key=mod_5))    # 14

Here, max returns the number whose remainder when divided by 5 is largest.


Booleans and Conditionals

1.Booleans

Booleans represent True or False.
You can convert values to booleans using bool():

print(bool(1))     # True  (all numbers except 0 are truthy)
print(bool(0))     # False
print(bool("Hi"))  # True  (non-empty strings are truthy)
print(bool(""))    # False (empty strings are falsey)

Empty sequences ("", [], ()) are falsey; everything else is truthy.

You can even use non-boolean values in if statements:

if 0:
    print(0)
elif "spam":
    print("spam")  # This prints because "spam" is truthy

2.Conditionals (if, elif, else)

Conditionals let your program choose which code to run:

weather = "sunny"

if weather == "sunny":
    print("Go outside!")
elif weather == "rainy":
    print("Take an umbrella.")
else:
    print("Stay home.")

3.Comparison Operators

OperatorMeaningExample
==equal to5 == 5
!=not equal to3 != 4
>greater than10 > 8
<less than2 < 5
>=greater or equal7 >= 9
<=less or equal4 <= 4

4.Combining Conditions (and, or, not)

Logical operators combine or invert conditions:

age = 20
has_ticket = True

if age >= 18 and has_ticket or age == 16:
    print("You can enter!")

Here, and is checked before or, so age >= 18 and has_ticket runs first.

Wrapping Up – Part 1

We’ve covered the Python basics — variables, data types, operators, and type conversions. These are your building blocks for any Python program.
Next, we’ll move on to working with collections like lists, tuples, strings, and dictionaries to store and manipulate data more effectively.

0
Subscribe to my newsletter

Read articles from Krupa Sawant directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Krupa Sawant
Krupa Sawant