Quick links
Latest articles
Internship
Members
New...
Algorithms
Discrete Mathematics
Big data
Languages
C
C++
C++ STL
Java
Data Structure
C#.Net
Android
Kotlin
SQL
Web
PHP
Python
JavaScript
CSS
Ajax
Node.js
Web prog.
Programs
C
C++
DS
Java
C#
Python
Aptitude
C
C++
Java
DBMS
Interview
C
Embedded C
Java
SEO
HR
CS Subjects
CS Basics
O.S.
Networks
DBMS
Embedded Systems
Cloud Computing
Machine learning
CS Organizations
Linux
DOS
More...
Articles
Puzzles
News/Updates

Home » Python programs

Python | Passing string value to the function



Here, we will learn by example, how to pass the strong value to the function in Python?
Submitted by IncludeHelp, on September 06, 2018

We have to define a function that will accept string argument and print it. Here, we will learn how to pass string value to the function?

Example:

Input:
str = "Hello world"

Function call:
printMsg(str)

Output:
"Hello world"

Program:

# Python program to pass a string to the function

# function definition: it will accept 
# a string parameter and print it 
def printMsg(str):
	# printing the parameter 
	print str

# Main code 
# function calls 
printMsg("Hello world!")
printMsg("Hi! I am good.")

Output

Hello world!
Hi! I am good.

Write function that will accept a string and return total number of vowels

# function definition: it will accept 
# a string parameter and return number of vowels 
def countVowels(str):
	count = 0
	for ch in str:
		if ch in "aeiouAEIOU":
			count +=1 
	return count 

# Main code 
# function calls 
str = "Hello world!"
print "No. of vowels are {0} in \"{1}\"".format(countVowels(str),str)

str = "Hi, I am good."
print "No. of vowels are {0} in \"{1}\"".format(countVowels(str),str)

Output

No. of vowels are 3 in "Hello world!"
No. of vowels are 5 in "Hi, I am good."





Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Featured post:
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distribution Software (Distros) of 2018

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates



© https://www.includehelp.com (2015-2018), Some rights reserved.