Home
User Guide
DB Recovery
Download
Documents
FAQ
Books
About Me
C programs
python programs
Stats
How To define and call a function in python to perform some string operations

# Comments in python is represented by # symbol.
#function definition is preceeded by keyword def
def fun_name(args):
	"""doc string""" # optional doc string ,to describe about function
	print args
	#String can represented by single/double/triple single quotes
	print '''to my ''' #this one uses triple single quotes
	print "opensource" # this one uses double quotes
	print 'world' 	 # this one uses single quotes
	print "GNU/Linux - Programmers Paradise"
	#assignment 
	word="Linux"
	#string manipulations
	print word[0] # prints first char.'L'
	print word[0:3] #prints first 3 chars 
	print word[3:] #prints starts from 3rd char.
	
	return None	#if nothing is returned ,use keyword None
#calling the function 
fun_name("Welcome");

#What you have learned with this program?
#How to define a function along with doc_string and how to call a function with a argument
#How strings are represented in python and manipulating it.
#A Return type called None.

Powered by
Open Source Programmers