Python Syntax Tutorial

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/python-syntax-tutorial/
PINTEREST
PINTEREST
INSTAGRAM

PYthon is practical and readable programming language. Python have different syntax from popular programming languages like C, C++, C#, Java etc. Python syntax makes it easy to learn. In this tutorial we will look some aspect of Python programming language syntax.

Identifier

Identifier is the one of the main topics of all programming languages.  Identifiers are used by programmer to specify some programming language structs like variable, class, function etc. Identifiers can start with lowercase and uppercase letters and underscore.

Numbers can be used in identifiers except first character

Valid Identifiers

Invalid Identifiers

Reserved Words

Python have already uses some words. These words provides programming language functionality to the programmer. We call this words reserved words. Reserved words can not be used as identifiers. Reserved words also called Python keywords. All reserved words are lowercase letters only. Here list of Python reserved words.

andexecnot
assertfinallyor
breakforpass
classfromprint
continueglobalraise
defifreturn
delimporttry
elifinwhile
elseiswith
exceptlambdayield

Comments

While writing python applications we may want to take notes on the code or we simply need to explain what the code, function, class, variable do. This notes are called Comments and can be written with # sign. Comment lines are not interpreted or used by python they are just text not a instruction.

LEARN MORE  Java - Basics and Comments

Comments can be also start after an instruction line like below.

Lines and Indentation

One of the pythons most interesting feature is indentation. While developing application we need to group instructions and create blocks. In python we use indentation in order to group or create block. The number of spaces in indentation is variable but must be the same in all of the file. If it is not the same we will get error and code will no run.

Following is an example where we used 3 spaces as indentation and will work perfectly.

Blank Line

There is no meaning blank lines in Python programming language.

Multi Line

Normally each line is used for new instruction. So we can not use multiple lines for the same instruction this is the nature of the Python. But \ can be use to provide multi line instructions which makes given lines like a single line.

But one more exception is [],{},() can be used in multiple lines without \ .

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/python-syntax-tutorial/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)