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 allows two modes of programming:
1. Interactive Mode Programming
2. Script Mode 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:
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”);
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:
2. This will open a new file. Type the following statement in it:
Print (“Hello World”);
3. Save your file with .py extension
4. Now go to Run>Run Module as shown below:
5. The interpreter will now execute the file and display the result.
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!!");