MediumPython Syntax. Python syntax are the rules which every… | by Akshayachitti | Nov, 2026 | Medium
Sitemap

Python Syntax

4 min read1 day ago

--

Python syntax are the rules which every python programmer has to follow while writing the instruction.

If you don’t follow the instructions, it will get an error,that error is called syntax error.

Statement

Statement is a instruction which our python engine can execute.

Types of statements in python

  1. Single statement in single line

One statement in one line

Example

2. Multiple statements in single line

We can write multiple statements in single line by using the symbol semicolon ;

Example: Without using semicolon

without using semicolon

Example: With using semicolon

With using semicolon

3. Single statement in multiple lines

We can write single statement in multiple lines by using the symbol backslash(\) or parentheses(()).

Example: Whenever you want to break the statement then use backslash

using backslash

Example: Using parentheses

What is comment

Comment is a instruction will be ignored by python engine.

Whenever, we are writing any instruction in python programming language always python think entire instruction is statement.

Use the symbol # hash to write the comment.

What is keywords

Keywords are reserved words that have special meanings in python.

Example: if,else,for etc

Variables in python

What is variable?

A variable is a container used to store data in python .

What is data?

Data is a collection of information.

Get Akshayachitti’s stories in your inbox

Join Medium for free to get updates from this writer.

What is a variable name?

A variable name is the name given to a variable.I helps us to identify the data stored .

When do we use variables?

We use variables whenever we want to store and reuse data again and again.

Variable = data(= is assignment symbol)

Example

x is a variable name

= is a assignment symbol

10 is a data value

Naming convention in python

What is naming convention?

Naming convention is a set of python rules follows and create a variable name.

Rules of naming convention

  1. A Variable name should always start with alphabets or an underscore(_).

Examples: Variable starting with alphabet or underscore ,so it is valid.

Variable starting with alphabet or underscore that’s why it is valid

Variable is not starting with alphabet or underscore,it starting with number so the output is error that error is called syntax error.

The variable starting with number ,so the output will come error.

2. Variable name should not contain any special symbols or characters except underscore.

Example:Variable is not containing any special symbol (except _)

Press enter or click to view image in full size

3. Variable name can contain numbers( not as the first character)

Example: Variable not containing with a number as a first character.

Variable containing first character as a number so the output is syntax error.

4. Python is a case sensitive language.

Python treats uppercase and lowercase letters as different characters.

Example

5. Never use keywords as a variable name.

Keywords are reserved words in python. They have a special meanings, so we cannot use them as a variable name.

--

--