Enrich your knowledge with our informative blogs
Unlike C/C++ python is an interpreter-based high-level programming language.
Python is widely popular because:
Why python is the first choice of programmers, gamers and other professionals of the digital world?
Python is highly readable language that is read by a parser line by line. The language follows a syntax which is a set of rules that tells how a program or the instructions would be written.
Let’s discuss the Line structure in Python.
Line structure
In a Python code, every instruction is in the form of a line. Each line is terminated by a carriage return of NEWLINE.
This line can contain spaces, tabs, characters, comment etc. each line is like a statement.
Here, we will be discussing syntax based on Python3.
For example: Have a look at the following Python statements.
print(‘User Id: ‘, 15)
print(‘First Name: ‘, ‘Harry’)
print(‘Last Name: ‘, ‘Potter’)
These are single line statements followed by a carriage feed or newline character. To join multiple lines, you will need “\” or backspace.
“\” is used to split one statement or instruction. It does not join two different lines (instructions).
Let’s take some more examples for multiple lines.
if subject > 10 and \
totalmarks >= 300:
print(‘You have created history!’)
Indentation:
To define the program blocks, Python uses whitespaces which can either be spaces or tabs.
Unlike most of the programming languages like C/C++ uses braces {} to define a block, it’s just white spaces for Python code.
Though indentation is not fixed, every statement within the block must be indented in a same manner.
Indentation Rules
Comments in Python
In Python, comments always begin with #. Here “#” is not a set of literals that are used in python programming.
Whatever is written after # till the end of line, python interpreter ignores it.
Python Identifiers
An identifier in python means any name that is used to identify a function, variable, object, class etc.
It starts with letter a-z or A-Z or can start with “_” (underscore). The name can then followed by numbers or other letters.
No punctuation characters such as $, @ and % are allowed within the identifiers.
The identifiers are case sensitive. “school” and “School” are two different identifiers.
Have a look at some naming conventions in Python identifiers:
Read More – Coding and Programing Questions
View More – Useful links for Your Child’s Development
Unleash the power of true logic building with Real-time instructions and live coding exposure.