Placement Prep

Python Tutorial for Beginners: Hello World to Functions

Start Python in 2026: write Hello World, learn variables, types, control flow, and functions, then build FizzBuzz. Covers placement DSA and AI prep.

By FACE Prep Team 6 min read
python python-tutorial beginners placement-prep dsa programming

Python tops coding-round acceptance at most Indian campus placement drives, runs every major AI/ML framework, and takes about 30 minutes to get from zero to a first running program.

This tutorial is for engineering students who have never written a line of Python and want a direct path from Hello World to solving basic placement problems.

Why Python in 2026

Python’s dominance in technical hiring has two independent drivers, and both apply to Indian placement students.

The first is placement coding rounds. TCS, Infosys, Wipro, Cognizant, Capgemini, and most mid-tier IT services companies accept Python in their online coding assessments. The TIOBE Index has ranked Python as the world’s most popular language every month since early 2022, and the Stack Overflow Developer Survey 2024 listed it as the most-used language for the fourth year running. Interviewers who write coding-round problems expect Python solutions to be readable and short. A FizzBuzz solution in Python is 8 lines; the equivalent in Java is closer to 15.

The second driver is AI and ML. NumPy, pandas, scikit-learn, PyTorch, and every major LLM library have Python as their primary interface. If you plan to work in data science, machine learning, or any AI-adjacent role, Python is not optional.

For an engineering student whose placement season starts in 6 to 12 months, Python covers both tracks with a single investment in learning one language.

Your First Python Program

Download Python 3 from the Python official tutorial page and install it from python.org. On Windows, check the “Add Python to PATH” box during installation. On macOS and Linux, Python 3 is usually pre-installed; verify with python3 --version in the terminal.

The interactive REPL

Open a terminal and type python3. You land in the interactive shell, called the REPL (Read-Eval-Print Loop). Type any expression and press Enter to see the result immediately:

>>> 2 + 3
5
>>> "hello" + " world"
'hello world'
>>> type(42)
<class 'int'>

The REPL is the fastest way to test small expressions without writing a file. Use it constantly while learning.

Hello World as a file

Create a file called hello.py and add one line:

print("Hello, World")

Run it from the terminal with python3 hello.py. The output is:

Hello, World

print() is a built-in function that writes text to the screen. Parentheses are mandatory. Strings go inside quotes (single or double, and Python treats both identically).

Variables and Core Data Types

A variable in Python is a name that points to a value. You don’t declare a type; Python infers it at runtime. This makes Python faster to write than statically typed languages, which is one reason it dominates quick-turnaround placement coding rounds.

score = 95           # int
gpa = 8.7            # float
name = "Arjun"       # str
is_placed = True     # bool

Python’s five most-used types in placement-level code:

TypeExampleNotes
int42, -7Whole numbers, no size limit
float3.14, -0.5Decimal numbers
str"hello", 'world'Text, immutable
list[1, 2, 3]Ordered, mutable sequence
dict{"name": "Arjun", "score": 95}Key-value pairs

There is also tuple, an immutable list: (1, 2, 3). Tuples are used when the data should not change after creation. A good rule of thumb: if the collection is a fixed set of coordinates, settings, or labelled constants, use a tuple; if it will grow or shrink, use a list.

Use type() to inspect any variable:

x = [10, 20, 30]
print(type(x))   # <class 'list'>

Accessing list and dict elements:

marks = [85, 90, 78]
print(marks[0])          # 85  (zero-indexed)

student = {"name": "Priya", "cgpa": 8.9}
print(student["name"])   # Priya

For more worked examples of these types in action, the Python example programs for practice page has a set of short programs you can run and modify immediately.

Control Flow: if, for, and while

Conditions with if/elif/else

Python uses indentation (4 spaces by convention) to define blocks (no curly braces).

marks = 72

if marks >= 75:
    print("First class")
elif marks >= 60:
    print("Second class")
else:
    print("Pass class")

Comparison operators: == (equal), != (not equal), < (less than), > (greater than), <= (less than or equal), >= (greater than or equal). In prose and code comments, always wrap these operators in backticks when describing them outside a code block.

The for loop

range(start, stop) generates integers from start up to but not including stop. Default step is 1.

for i in range(1, 6):
    print(i)   # prints 1 2 3 4 5

You can also iterate directly over a list:

colleges = ["NIT Trichy", "BITS Pilani", "VIT Vellore"]
for college in colleges:
    print(college)

For a hands-on extension of for-loop logic, the greatest of three numbers in Python program shows how to chain comparisons inside a block to find a maximum value.

The while loop

Use while when the number of iterations depends on a condition rather than a count:

n = 1
while n <= 5:
    print(n)
    n += 1

n += 1 is shorthand for n = n + 1. Without incrementing n inside the loop body, the loop runs forever. That is the most common beginner bug with while.

Writing Functions

A function groups reusable logic under a name. Syntax: def keyword, function name, parentheses, colon, then an indented block.

def greet(name):
    return "Hello, " + name

print(greet("Ravi"))   # Hello, Ravi

Default arguments

Give a parameter a default value so it becomes optional at the call site:

def power(base, exponent=2):
    return base ** exponent

print(power(3))     # 9   (uses default exponent=2)
print(power(3, 3))  # 27  (overrides default)

Functions can call other functions and grow as complex as a project demands. A simple calculator in Python is a good next exercise: four functions (add, subtract, multiply, divide) wired to a menu, using everything from this section in a realistic program.

A Worked Example: FizzBuzz

FizzBuzz prints numbers 1 to 100 with three substitution rules:

  • If the number is divisible by both 3 and 5, print FizzBuzz.
  • If divisible by 3 only, print Fizz.
  • If divisible by 5 only, print Buzz.
  • Otherwise, print the number.

The % operator returns the remainder of integer division. A quick REPL check:

>>> 15 % 3
0
>>> 15 % 5
0
>>> 7 % 3
1

Check divisibility by 15 first. If you check 3 and 5 separately before checking 15, a number like 15 would print Fizz and stop; the combined case would never be reached.

def fizzbuzz(limit):
    for i in range(1, limit + 1):
        if i % 15 == 0:
            print("FizzBuzz")
        elif i % 3 == 0:
            print("Fizz")
        elif i % 5 == 0:
            print("Buzz")
        else:
            print(i)

fizzbuzz(100)

Walk-through for a few values:

  • i = 3: 3 % 15 = 3 (not zero), 3 % 3 = 0 — prints Fizz
  • i = 5: 5 % 15 = 5 (not zero), 5 % 3 = 2 (not zero), 5 % 5 = 0 — prints Buzz
  • i = 15: 15 % 15 = 0 — prints FizzBuzz
  • i = 7: none of the conditions match — prints 7

The function takes limit as a parameter so it’s reusable for any range. That habit separates readable code from one-off scripts.

Interviewers ask FizzBuzz to check three things in under two minutes: that you can write a loop, use modulo arithmetic, and order your conditions correctly. The same if/elif/else pattern appears in almost every coding-round problem that involves bucketing or classification.

What to Learn Next

The six topics in this article (Hello World, types, conditions, loops, functions, and one working program) are the foundation for every Python problem in a placement coding round.

From here, the natural next steps are: sorting algorithms (selection sort, bubble sort, merge sort) using lists; string manipulation (slicing, join, split); and recursion (factorial, Fibonacci). The Python example programs for practice page has short programs for each of these that you can run and modify.

The % operator and the if/elif chain from FizzBuzz show up constantly in AI/ML preprocessing scripts as well: bucketing continuous values, filtering datasets, routing inputs through conditions. If you want to apply those same patterns to language model tasks, TinkerLLM is a hands-on LLM playground at ₹299 where the Python you built here becomes the interface to real AI projects.

Primary sources

Frequently asked questions

Is Python a good first language for placement prep in 2026?

Yes. Most Indian placement drives accept Python for coding rounds, and interviewers expect candidates to know basic syntax like loops, conditions, and functions. Python also runs every major AI/ML framework, so the skill transfers directly to AI-focused roles.

What version of Python should I install?

Install Python 3.12 or the latest 3.x release from python.org. Python 2 reached end-of-life in 2020 and is no longer supported or used in any modern placement or production context.

What is the difference between a list and a tuple in Python?

A list is mutable — you can add, remove, or change elements after creation. A tuple is immutable — once created, it cannot be changed. Use a list when the collection will change (e.g., scores to append), and a tuple when the collection is fixed (e.g., RGB colour coordinates).

How does the for loop work in Python?

A for loop in Python iterates over any sequence: a list, a range, a string, or a tuple. The syntax is `for variable in sequence:` followed by an indented block. For example, `for i in range(1, 6):` iterates with i taking values 1, 2, 3, 4, 5 in order.

What is FizzBuzz and why do placement rounds ask it?

FizzBuzz is a classic coding problem: print numbers 1 to 100, but print Fizz for multiples of 3, Buzz for multiples of 5, and FizzBuzz for multiples of both. Interviewers use it to check that a candidate can write a loop, use modulo arithmetic, and chain conditions — all in under two minutes.

Build AI projects

A self-paced playground for building with LLMs.

TinkerLLM is FACE Prep's sister property. A guided environment for shipping real LLM applications, the kind of project that earns a paragraph on your resume, not a line.

Try TinkerLLM (₹299 launch)
Free AI Roadmap PDF