Python Syntax
What is Python?
Python is a High-Level Programming Language.
The High-Level Programming Language is a set of instructions written by the human beings to communicate with the Low-Level Programming Language.
The Low-Level Programming Language is completely the machine understandable language that in the form of 0’s & 1’s is called as Binary Language.
A High-Level Programming Language goes through a translator that converted into Low-Level Programming Language.
The translator acts like a communicator between human and computer(machine).
And python is also a case-sensitive language.
What is a Syntax?
Syntax refers to the set of rules and structure of the programming language to write the correct code.If there was any character or elements like brackets,punctuations(quote) are missing then the python get confused and raises an syntax error.
What is Statement?
Statement is an instruction or a command given by the user that can execute by the python engine.
Example: y=15
hence,it tells the computer to store 15 in y.
Statement is divided into 3 types of statements they are:
01. Single Statement in Single Line: A sentence in one line is called as single statement in single line.This statement is easy to read and understand.Multiple statement in multiple line is same as the single statement in single line.
Example:(1) #single statement in single line
12+10
Output: 22
(2) #multiple statement in multiple line
2+3
7+1
2+2
Output: 4
02.Multiple Statement in Single Line: A multiple sentences in one line is called as multiple statement in single line.Here, we use the semi-colon( ; ) between the two statements.In this the code readability decreases.
Syntax: S1 ; S2 ; S3
Example: #multiple statement in single line
2+6;10+2
Output: 12
03.Single Statement in Multiple Line: One sentence in multiple lines is called as single statement in multiple line.Here, we use the backslash( \ ) or parentheses( ) for the purpose of the breaking the code.
Example:
(a) backslash:
#single statement in multiple line
6–2\
+3+\
9
output: 16
(b) parentheses:
Get M.Anjali’s stories in your inbox
Join Medium for free to get updates from this writer.
#single statement in multiple line
(1+
2
+
3-
5)
Output: 1
Comment: A comment is an instruction will be ignored by the python engine.To make the code readable then comment is used.Here we use comment symbol as Hashtag(#).
A comment symbol written before the statement so, that the line of a code is called as comment line is ignored by python engine and easy to understand and readable to users.
There is no multiple line comment only single line comment which we can create multiple lines.
Example: #comment
m=12#storing 12 in m
m
output: 12
Keywords: keywords are the reserved words in python which have a special meaning inside the python engine.
There are 35 reserved keywords in the python.Reserved keywords like if,else,return,True,False.
Variables: variables are the first pillar of the python.The variables are used to store the data in the computer.To use the data again and again then the variable is used.
Firstly, we need 3 steps to store data:
- Create the data.
- Assign the variable to the data.
- Store the data.
Syntax: variable name = data
here, the data is stored in the variable name by using the assignment symbol( = ).
Naming Convention: The naming convention has the set of rules to create a variable name.The naming convention have few rules which follows:
- Variable name should always starts with an alphabet or underscore(_):-
Example: User,xyz,_id
10dx,2y are raises an syntax error.
2. Variable name should not contain any special symbol or character except underscore(_):-
Except alphabet or numbers is called special symbols.
3. Variable name can contain numbers after the first character:-
Example: bk125lh,A235
4. Python is a case-sensitive language:-
Case-sensitive treats the uppercase and lowercase in different.
Example: a=48
A=94
5. Never use keywords as a variable name:-
Example: true=65
true
output: 65





