Python Syntax

In this chapter Python are very similar to other language php,perl etc.

Basic Python syntax

We can execute directly by using command line

>>>print ("Hello, world!")

Hello ,world!

We need to print statement with parenthesis as in print ("Hello, world!")

We can execute server side .py file extensionwindow

C:\Users\Your Name>python test.py

We can execute server side .py file extensionLinux

$ python test.py

This produces the following result −

Hello, world!

Comments in Python

Comment are start with #, up to end of end of physical line are part of comment.

Comments are up to the end of the physical line are part of the comment.


#!/usr/bin/python #This is comment line
# First comment
print "Hello, Python!"# second comment
Try it yourself »

Multi-Line Statements

Multi line comments allow the use of the line continuation character (\) to denote that the line should continue.

sum= item1 + \ item2 + \ item 3

Python Identifiers

Python the indentation is very important.ends with two trailing underscores, the identifier is a language-defined special name


if 2>1;
print(" two is greater than one")
Try it yourself »

In the next chapter you will learn about variable