Python Syntax
1. Introduction :
Python syntax refers to the set of rules that we follow while writing Python programs. It tells us how to write code correctly so that the Python interpreter can understand and execute it.
2. Basic Python Syntax
Example :
print(“Hello World”)
Output:
Hello World
3. Variables :
Variables are used to store data values in a program.A variable is a name given to a memory location.We can store different types of data, such as numbers, strings, and decimal values.The value of a variable can be changed during program execution.
Example:
a = 10
b = 20
print(a)
print(b)
Output :
10
20
4. Comment :
Comments are used to explain the code.They make the program easy to understand.Comments are not executed by the Python interpreter.In Python, we use the # symbol to write single-line comments.
Example:
# This is a comment
print(“Hello Python”)
Output :
Hello Python
5. Indentation :
Indentation means giving spaces at the beginning of a line. Python uses indentation to define blocks of code.
Example:
if 10 > 5:
Get Amanithota’s stories in your inbox
Join Medium for free to get updates from this writer.
print(“10 is greater”)
Output:
10 is greater
6. Data Types :
Data types define the type of data stored in a variable.
Examples:
int — Integer numbers
float — Decimal numbers
str — Text
bool — True or False
Example:
a = 10
b = 10.5
c = “Python”
d = True
print(type(a))
print(type(b))
print(type(c))
print(type(d))
7. Operators :
Operators are used to perform operations on values.
Example:
a = 10
b = 5
print(a + b)
print(a — b)
print(a * b)
print(a / b)
Output:
15
5
50
2.0
8. Conditional Statements :
Conditional statements are used to make decisions in Python.
Example:
a = 10
if a > 5:
print(“A is greater than 5”)
Output:
A is greater than 5
9. Conclusion :
Python syntax is very easy to learn and understand. By learning basic concepts like variables, comments, indentation, data types and operators, we can write Python programs easily. It helps us to improve our programming skills.



