MyInternships.in

Python Basics

Python Syntax

Python syntax refers to the set of rules that define how a Python program is written and structured. Getting these basics right avoids most beginner errors.


Indentation Matters

Unlike many languages that use curly braces {} to group code, Python uses indentation (spaces at the start of a line) to define blocks of code, such as the body of a loop or a function. Consistent indentation is not just a style choice in Python — it is required syntax.

Indentation defines a block
Python
age = 20
if age >= 18:
    print("You are an adult")
    print("You can vote")
print("This runs regardless")
⚠️

Mixing tabs and spaces, or using inconsistent indentation, causes an IndentationError. Stick to 4 spaces per level.

Statements

A statement is a single instruction that Python executes, like assigning a variable or calling a function. Normally, each statement sits on its own line and you do not need a semicolon at the end, unlike languages such as Java or C.

Simple statements
Python
name = "Riya"
print(name)

Case Sensitivity

Python is case-sensitive, which means Name, name and NAME are treated as three completely different variables.

Python
name = "Amit"
Name = "Priya"
print(name)
print(Name)

Line Structure

Python generally expects one statement per line. If a line of code is too long, you can break it using a backslash or by wrapping it inside brackets.

The print() Function

The print() function is the most common way to display output on screen, and you will use it constantly while learning and debugging.

Python
print("Learning Python syntax step by step")
💡

Good indentation habits early on will save you hours of confusing errors later when you write functions and loops.

Related Python Topics

Keep learning with these closely related lessons.

Ready to use your Python skills?

Find Python, data science and software internships and fresher jobs across India.

Browse Python Internships