Navigation Menu

Approach to Python Programming



Python is a general-purpose interpreted, interactive, object-oriented, and high level programming language.

It supports functional and structured programming methods as well as OOP.
It can be used as a scripting language or can be compiled to byte-code for building large applications. It can be easily integrated with C, C++, Java.

Environment Setup


Download python from website http://www.python.org/.


Install the downloaded file.





After installing setup the path to command prompt.






Writing a First Program

Notepad is the best environment to write program easily and can be executed through command prompt.

Step1: Write a program in notepad.



Step2: Execute through command prompt.



Creating Variables

We no need to create variables in python. Variables are created while assigning a to them.




Conditional Statements

1. If() statement:

Syntax: if  condition:
                // statements
                // statement





2. if..else() statement:

Syntax: if condition:
                     // statements
            elif consition:
                     // statement
            else
                    // statements






Looping Statements

1. for() loop:

Syntax:  for variable in Collection:
                  //statements(s)






2. while() loop:

Syntax: while(<condition>):

                  // statement(s)






String Manipulation

1. Accessing Characters from string.





2. Updating String.




3. Special String Operators.




4. String Formating Operator.






5. index() method:

Syntax: source_string.index(destination_station,start_index,length)





5. find() method:




5. substring:





Reading Keyboard Input

Python provides two built in functions to read input from users.

1. input()






File Handling in Python

1. Reading a file

Step1: Input a file





Step2: Write a Program




Step3: Execute




Example : Parsing Menu

Step1: Program



Step2: Input file



Step3: Output



Step4: Output through text file







0 comments: