Sitemap
Sehwagbaipalli

Sehwagbaipalli

Python Syntax

3 min readNov 15, 2026

--

Syntax means the rules of a programming language . Just like English has grammar rules, every programming language has its own rules for writing instructions . Python also has certain rules that programmers must follow when writing code.

Example:

a=5+7
print(a)

python engine reads and executes the code -> 12

a=5+7-
print(a)
Press enter or click to view image in full size

Python engine reads , executes the code and shows the syntax error called invalid syntax.

Why is Python syntax important?

  • Helps us write correct Python programs.
  • Makes code easier to read and understand.
  • Prevents syntax-related errors.
  • Helps the Python interpreter understand our instructions.
  • Syntax errors occur when Python’s grammar rules are violated.

Statement:

A statement is an instruction written in a programming language that Python executes.

a=5+8
b=8-3
c=a+b
print(c)

It has three types:

  1. Single statement in single line : A statement written on one line.

2. Multiple statement in multiple line :A program can contain multiple statements written on different lines.

3. Single statement in multiple line : Python allows a single statement to continue across multiple lines.

Get Sehwagbaipalli’s stories in your inbox

Join Medium for free to get updates from this writer.

You can use a backslash (\) for explicit line continuation.

Comments in python:

Comments are notes written inside a program to explain the code . Python ignores comments during normal program execution . The “#” symbol is used to write a single-line comment.

Why use comments?

  • To explain the purpose of code.
  • To make programs easier to understand.
  • To help other programmers understand your logic.

Key words in python:

Keywords are special reserved words that have predefined meanings in Python.We cannot use these reserved words as variable names.

true is variable name so it prints the value,but in second condition it is not variable name so it shows syntax error. ‘True’ in python is predefined function or pre reserved word it is boolean function . this is the reason we never use key words as variable names.

Variables in python :

A variable is a name used to store or refer to a value in a program.

var_name=value

var_name —>variable(container or box name)

= is an assignment operator (value or date assigned to named container )

value —> data which is stored in variable(data stored or present in container or box)

x and spy_23 are variable names.

10 and 10000 are values which is assigned to that variables.

Python uses the assignment operator (=) to assign a value to a variable.

Naming convention or rules of creating variable name :

  1. Always starts with alphabet or underscore(_).
  2. does not contain any special character like @, $, spaces etc.
  3. can contain numbers too.
  4. it is case sensitive.
  5. Never use keywords or predefined words as variable names.

--

--