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 – Questions and Answers
Q 1: What is Python syntax?
Ans: Python syntax defines the rules for writing valid Python code.
Q 2: Does Python use braces {}?
Ans: No, Python uses indentation instead of braces to define code blocks.
Q 3: Is Python syntax case-sensitive?
Ans: Yes, Python treats uppercase and lowercase letters differently.
Q 4: What is indentation in Python?
Ans: Indentation is the spacing used to group statements into blocks.
Q 5: Does Python require semicolons?
Ans: No, semicolons are not required in Python.
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))