× About Us How it works Pricing Student Archive Subjects Blog Contact Us

Enrich your knowledge with our informative blogs

Describe the basic syntax of python

Unlike C/C++ python is an interpreter-based high-level programming language.  

Python is widely popular because:  

  • It is open source and free to use as well as carries a GPL-compatible license.   
  • Here, the instructions are processed line by line.  
  • This language supports all the OOPs concepts as well such as inheritance, modules, classes, objects etc.   
  • The language has incredible exception handling support and amazing memory management.   

Why python is the first choice of programmers, gamers and other professionals of the digital world? 

  • Enhanced readability 
  • It’s open source and a cross-platform language 
  • Modules from other languages can easily be integrated. 
  • It has become an integral part of Data science, AI, machine learning, web development, game development etc. 
  • Staggering support to other languages and modules. 

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 

  • All the instructions in a block use same indentation levels (same whitespace or same tab spacing). 
  • Generally four white spaces are used to denote indentation from the previous block. 
  • One block can have further inner levels by giving suitable indentation.  
  • To start a block you should use a colon (:)  and then hit Enter.  

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: 

  • All identifiers except class names start with lowercase letters. 
  • Identifier named using a one underscore means that it is a private identifier. 
  • A name starting with two underscores means additionally strong private identifier. 
  • Any identifier name ending with two underscores means it’s a language defined name.  

 

Read More – Coding and Programing Questions

View More – Useful links for Your Child’s Development 

Unveil your gateway to a lucrative career!
Unveil your gateway to a lucrative career!

Unleash the power of true logic building with Real-time instructions and live coding exposure.

Book A Demo Class

Tel Guru
Tel Guru

Register For The Demo Class

[footer-form]