Python Tutorial

What is Python?

Python is a very powerful yet simple and powerful language. Python instructions are understood and executed by an interpreter known as ‘Idle’. Idle is part of standard distribution of Python.

Python has two major versions 2 and 3. This tutorial is based on version 3. There is little difference in the two versions in the sense that there may be some difference in the way some instructions are invoked.

Python Shell

Modes of Programming In Python

Python allows two modes of programming:
1. Interactive Mode Programming
2. Script Mode Programming

Interactive Mode of Programming

In interactive mode you can pass the instruction directly to the interpreter without passing any script file.
So, if you go to the Python Idle directly and write 2+2 then it will give the output 4 as shown below:
Python Shell
Same way if you have to print “Hello world” directly on the Interpreter you just need to write the following statement on the interpreter and press enter.
Print (“Hello World”);
Interactive Mode

Script Mode of Programming

In the script mode of programming the execution of instructions takes place when you pass a script as a parameter to the interpreter.

Steps involved in creating a simple “hello world” script is as follows:
1. In the python shell go to File > New to open a new file, as shown below:
Script Mode step 1

2. This will open a new file. Type the following statement in it:
Print (“Hello World”);
Script Mode step 2

3. Save your file with .py extension
Script Mode step 3

4. Now go to Run>Run Module as shown below:
Script Mode step 4

5. The interpreter will now execute the file and display the result.
Script Mode step 5


1. Identifiers are used to name variables, class, function , modules or objects.
2. Identifier can start with a capital or small letter.
3. It can have digits and underscores and digits.
4. Punctuation character cannot be used for identifiers.
5. Class name identifier must start with a capital letter. Rest of the identifiers can start with smaller case letters.
6. If your identifier starts with an ‘_’ then it would be treated as private. Two underscores ‘__’ at the beginning of an identifier will make it strongly private.
7. Reserved words cannot be used as identifier names.

Python does not use braces rather it identifies a block of code with how the lines are indented. All statements of one block need s to be indented by equal space.

New line means a new statement unless:
1. A line continuation character(\) is used.
2. A bracket of any kind: (), {} or [] can have multiple lines.
Comments in Python start with a hash #

# this is hello world in python
print ("Hello world!!");

Download the code Run the code

Python variables and types >>>
Copyright 2005-2016 KnowledgeHills. Privacy Policy. Contact .