Python: Simple Function example

person Jason Huangfolder_openCode, Pythonlocal_offer, , access_time April 1, 2016

In Python, to define a function is very easy. use the def to define a function, you can then call the function directly by name.

For example:

 


#function example
def mod_string(msg):
   msg += " modified! "
   return msg
 
test_str = "this is a test"
print(mod_string(test_str))


The example function simply append ” modified” to the end of the string you passed into the function.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>