Python(Structure & Syntax)#4


Most programming languages use certain characters or keywords to group statements like below
‘{…}’ : for language like C/C++, JAVA etc.
do … done
if … fi
begin … end
Python uses a different principle. Programs get structured through indentation, this means that code blocks are defined by their indentation.

So, how does it work? All statements with the same distance to the right belong to the same block of code, i.e. the statements within a block line up vertically.

Note: A statement can be continued on the next line with the continuation character “\”.

You can write python in two different ways
Interactive Mode Programming
Script Mode Programming
Interactive Mode Programming
With the Python interactive interpreter it is easy to check Python commands. The Python interpreter can be invoked by typing the command “python” without any parameter followed by the “return” key at the shell prompt and rings up the following prompt â


>>> print (“Hello, World!!”)

This produces the following result â

Hello, World!!

Script Mode Programming
To Invoke the interpreter with script, you need to save your python program in a file with an extenson .py and then run the below command to execute the program.

For Example:-
Type the following source code in a test.py file

print (“Hello, World!”)

Now, try to run this program as follows
# On Mac/Linux
$ python test.py

On Windows
C:\Python34>Python test.py

This will print “Hello World!” on console.

Leave a comment

Design a site like this with WordPress.com
Get started