Sitemap
Manchirala Arun Kumar

Manchirala Arun Kumar

Python Syntax

4 min readJun 9, 2024

Definition of Python Syntax :

It contains a set of rules which programmer has to follow while writing an instruction in a Python Programming Language.

Statement or Expression :

A statement in a Python Programming Language is a single set of instruction in which your python engine can execute.

Single Line Statement :

Whenever the programmer is writing a statement should be written in a single line.

Below is the example of syntax error. when you write two statements in a single line without following a set of rules in Python Programming Language then it will throw an syntax error.

Single Line Statement In Multiple Line :

Single line statement looks like in python is 3 + 2 – 3.

Example of Single Line : 3 + 2 – 3

Whenever you want to break the line there we will use ( \ ) character. For suppose if you do not use Backslash ( \ ) character and you try to write a single statement in a multiple lines then it will throw syntax error.

  1. You can see Example of single statement in multiple lines is shown in below Image without \ character in 1st code .It throws syntax error.

2. You can see the below image of 2nd code which executes and gives output as 2 . Following the python syntax rule is mandatory and here we have used \ character to break the line.

Press enter or click to view image in full size

Multiple statement in a single line ( ; ) :

We can write a multiple statements in a single line by using Semi Colon ( ; ) character. Example of multiple statements in a single line in Below Image a shown.

Press enter or click to view image in full size

Comments :

Get Manchirala Arun Kumar’s stories in your inbox

Join Medium for free to get updates from this writer.

It gives an explanation of particular code.

  • It is a set of rules /instructions which is executed by python engine is known as statement or expression.
  • A set of instruction which is ignored by python engine is called Comments.
  • Comment is denoted by # in python language. Which is used at starting character of a set of instruction.

Below image is the example of comments. How python engine is ignoring the code which is commented and it is generated output as blank.

Press enter or click to view image in full size

Identifiers :

It is nothing but they are the names given to an entity or object like class, functions,variables etc.

How to write a variable name (identifier):-

  1. Variable name should start with an alphabet or underscore ( _ ).
  • Ex :- ArunKumar or _Arun_kumar

2. Variable name can have a number but this shouldn’t be at starting of alphabet.

  • Ex:- Arun5kumar

3. Variable name should not contain any special characters.

  • Special characters are ! @ # $ % ^ & * ( ) — = + \ | [ ] { } ; : / ? . > .Except underscore.

4. Python is case-sensitive.thus, Line is different from line.

  • Box = 10 and box =10 both are different.

5. We can’t use keywords as variable-name which is already a special word in Python Programming Language.

Variable :-

  • It is a container to store the data.
  • Rule is ( Variable-Name Assignment-operator data)
  • Example of a Rule x = 2 .( Here x is variable-name , Equal sign ( = ) is assignment operator and 2 is a Data.
  • We can reuse the same data again and again.
  • Variable is a memory block inside the RAM (Random Access Memory).
  • It is a temporary name given to a block of memory inside a RAM.
  • RAM is a temporary storage.

Keywords :

Keywords are nothing but they are reserved words in Python Programming Language .Those words have a special meaning in PPL (Python Programming Language). There are total 36 keywords are present.

>>Next : Data Types

--

--