What is Python Syntax?
Syntax means the rules that define how a program should be written.
Python has a simple and readable syntax. Unlike some programming languages, Python uses indentation to define blocks of code.
Incorrect syntax can cause a
SyntaxError.
Python Statements
A statement is an instruction that Python executes.
name = "Sudhanshu"
print(name)
Here, the first line stores a value in a variable and the second line displays it.
Python Indentation
Indentation means adding spaces at the beginning of a line.
Python uses indentation to identify a block of code.
if 10 > 5:
print("10 is greater")
The spaces before
print()
show that it belongs to the
if block.
age = 18
if age >= 18:
print("You can vote")
Python is Case-Sensitive
Python treats uppercase and lowercase letters as different.
name = "Alex"
Name = "John"
print(name)
print(Name)
Here, name and Name
are two different variables.
Quick Quiz
Test your understanding of Python syntax.
1. Which symbol is used for a single-line comment?
Finished this lesson?
Comments in Python
Comments are notes written inside the program. Python does not execute comments.
A single-line comment starts with the
#symbol.Comments help programmers understand what different parts of the code do.