Python syntax refers to the set of rules that define how a Python program is written and interpreted.
Python has a simple, statement-based syntax. However, there are a few properties you need to know about.
Statements execute one after another, until you say otherwise.
There are no braces or begin/end delimiters around blocks of code in Python. Instead, Python uses the indentation of statements under a header to group the statements in a nested block.
Python statements are not normally terminated with semicolons.
1. Case Sensitivity
Python is case-sensitive, meaning that Var and var are treated as different identifiers.
2. Indentation
Indentation is used to define the structure of code blocks like functions, loops, and conditionals.
Python does not use curly braces {} or keywords like begin/end; it relies on consistent indentation.
if x > 2:
print("x is greater than 2")
3. Comments
Single-line comments start with a # symbol.
# This is a single-line comment
Multiline comments can be done using triple quotes ‘ ‘ ‘or”””:
'''
This is a
multi-line comment
'''
4. Variables
Variables do not need to be declared with a specific type.
Python dynamically assigns types based on the value assigned.
x = 20 # Integer
y = 5.67 # Float
name = "John" # String
Python Tutorial – Interview Questions
Q 1: What is Python syntax?
Q 2: Does Python use braces {}?
Q 3: Is Python syntax case-sensitive?
Q 4: What is indentation in Python?
Q 5: Does Python require semicolons?
Python Syntax – Objective Questions (MCQs)
Q1. Which of the following is the correct way to print a message in Python?
Q2. Which of the following is not a valid variable name in Python?
Q3. What is the correct indentation in Python used for?
Q4. Which of the following symbols is used to start a comment in Python?
Q5. What will be the output of the following code?
x = 5
y = "5"
print(x + int(y))