Python programming tutorials

StringString methods and applications
listOrdered changeable items list
tupleOrdered unchangeable items list
setUnordered and unindexed list
functionsUser defined function with Parameters handling
File handlingUser defined function with Parameters handling
Sample CodesSample codes in python
try catchHandling error in Python
Class & ObjectObject Oriented Programming in Python
iteratoriterator using iter()
for loopfor loop with break continue and else
generatorcreating iterator in python
tkinterAdding GUI in Python
BitwiseBitwise operators in Python
Database Management using Python
MySQLPython functions to manage MySQL database
NumPy ArrayScientific computing with Python
Array MethodsMethods to get result ( output ) using NumPy

indentation matters

Indent in Python codingBlock of codes are maintained by using same indent. Line of codes within a particular loop or if condition is maintained within the same indent. Nested loops also maintain the similar indenting condition.

printing output with format

name="Ronal Jack"
print("ID :{:02d} Name:{:15s} Mark: {:2d}".format(id,name,mark))
Output is here
ID :05 Name:Ronal Jack      Mark: 45
str1="Welcome "
str2=" to "
str3=" Python "
str4=" Your student id = "

print(" Hi {2} {1} {0} ".format(str1,str2,str3))
print(" Hi {0} {1} ".format(str4,id))
Output is here
Hi  Python   to  Welcome  
 Hi  Your student id =  5 
Correct the first line to get proper sequnce of words

Printing decimal upto 2 places using format

my_str="Mr ABCD"
name="Welcome to Python"

print("Hi {}, Your id = {}, Your Average ={:.2f})".format(my_str,id,avg))
Output is here
Hi Mr ABCD, Your id = 5, Your Average =356.23)
Python adds one line break after each print command, we can remove the line break ( Watch the end='' within the print ())
my_str="Mr ABCD"
name="Welcome to Python"

print("Hi {}, Your id = {} ".format(my_str,id),end='')
print("Your Average ={:.2f})".format(avg))
output is here
Hi Mr ABCD, Your id = 5 Your Average =356.23)

Printing using variables inside string

print("Hello ",b," to ", c )
Output is here
Hello  welcome  to  Python

Using escape char

Let us print I can't travel by bus
print(' I can\'t travel by bus')
We used escape char \ inside the word can't to print single quote instead of using as string termination.
We can use special char \ inside our string without using as escape char by adding r before the quotes
Here \t is not considered as Tab and the out put is here

We can add doble quote inside single quote
print ( 'We said "Welcome to plus2net"')
Output is here
We said "Welcome to plus2net"
Your Rating

Post your comments , suggestion , error , requirements etc here

HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 All rights reserved worldwide Privacy Policy Disclaimer