Home Search

Regent iTech - Software Training Institute

Corporate, Online and Classroom Trainng

Advanced Technology Hands On Training

Software Development - Mobile and Web

www.regent-itech.com   Call:9513325606

Python Tutorials - Programming Examples for freshers, Graduates and Engineers

Introduction

Open source general-purpose. Multiplatform programming language

Object Oriented, Procedural, Functional

Easy to interface with C/ObjC/Java/Fortran

Easy to interface with C++ (via SWIG)

Great interactive environment

Python 'philosophy' emphasis readability, clarity and simplicity

The Interactive Interpreter

Source can be compiled or run just-in-time

it is very easy to learn and understand

It is extensible, you can easily plug new modules in your Python installation and extend its functionality

Where python is used ?

Python is a very flexible language. It is widely used for many different purposes. Typical uses include :

Web Programming

System administration tasks via simple scripts

Desktop Applications

Windows Applications

Natural Language ToolKit

Large collection of proven modules included in the standard distribution

Offers Matlab-ish capabilities within Python

Fast array operations

2D arrays, multi-D arrays, linear algebra etc.

Wrappers for Astronomical Packages

Get Started

Installing Python

Download Python 3.5(32-bit and 64-bit versions of the interpreter ) which includes:

Python Software :

The standard library, test suite, launcher and pip will be installed

Development Environment

IDLE – a cross-platform Python development environment. Text editor with color-coding and smart indenting for creating python files Menu commands for changing system settings and running files. Shell for interactive evaluation.

Do not use Notepad - it is a bad choice because it does not do syntax highlighting and also importantly it does not support indentation of the text

Why IDLE

IDLE helps you program in Python by:

color-coding your program code

debugging

auto-indent

interactive shell

Write simple Python program

program 1 : #one.py

print('Hello World')

Ruuning python program in IDLE

Open New Window , enter program and save

Run and Run Module

Ruuning python program in command line

>> python one.py

Outpur :

Hello World

program2 : # kbinput.py

name = input('What is your name:')

print('It is good to meet you mr ', name)

Indentation

Whitespace:

Whitespace is important in Python. Actually, whitespace at the beginning of the line is important. This is called indentation. Leading whitespace at the beginning of the logical line is used to determine the indentation level.

This means that statements which go together must have the same indentation. Each such set of statements is called a block.

You cannot arbitrarily start new blocks of statements (except for the default main block which you have been using all along, of course).

How to indent:

Do not use a mixture of tabs and spaces for the indentation as it does not work across different platforms properly. Use a single tab or four spaces for each indentation level.

Note :Python will always use indentation for blocks and will never use braces

Comment:

Single line : Start comments with # – the rest of line is ignored

Multi line : “““This is the multi line comment .”””

Control Structure Programs

Program 3: command.py

# Using If and elif Statement - compute.py

a = input('enter value a:')

b = input('enter value b:')

x= int(a)

y=int(b)

ch = input('enter your option(1.add 2.subtract):')

choice= int(ch)

if choice == 1:

        print('sum of ' + a + 'and ' + b +'=', x+ y )

elif choice == 2:

        print ( ' subtraction of '+ a + ' and ' + b + 'is ' , x- y )

else:

        print('Invalid Option:')

Program 4 : inputText.py

x = input(‘enter char:’)

while( x != ‘quit'):

         x = input(‘Enter quit for exit):')

        if(x=='z'):

                break

        print(x)

print('done')

Program 5 : usingFor.py

val=input('enter the value for x')

x=int(val)

for i in range(x):

        if(i%2==0):

                continue

        print(‘value:’,i)

print('done')

Program 6 : sort.py

number=[8,5,4,3,6,3,1,2]

index=len(number)

for i in range(index):

        for j in range(i+1,index):

                if number[i]>number[j]:

                

        temp=number[i]

                

        number[i]=number[j]

                

        number[j]=temp

print(number)

print('numbers',':sort completed:')

Program : recursive.py

def printdata(msg,n):

        if n<=0:

                return

        else:

                print(msg)

                printdata(msg,n-1)

printdata('hello',6)

def countup(start,end):

        if start>=end:

                 return

                 print(start)

        else:

                 print(start)

                 start=start+1

        countup(start,end)

countup(5,15)

Office Address

No - 1328, 24th 'A' Main, 41st Cross, Jayanagar 9th Block, Jayanagar, Bangalore. Karnataka, India - 560041. Landmark :opposite to Ragigudda / Central Mall , Behind Big Bazaar, Near Jain University & Opposite to LensKart.com and Himalaya Drugs , Call : 9886272445 / 9513325606