Use of Python----functions

Source: Internet
Author: User

Tag:python    function    

1. A simple non-parametric function #!/usr/bin/evn python#filename: function1.pydef sayhello ():     print  ' hello world! ' SayHello () 2. function parameter #!/usr/bin/evn pyhon # filename: fun_param.pydef printmax (A, B):     if a > b:        print  a,  ' Is maxinum '     else:        print  b,  ' Is maxinum ' Printmax (3, 4) X = 5y = 7printmax (x, y) 3. Global Parameters #!/ Usr/bin/env python#filename : fun_global.pydef func ():    global  x    print  ' X is ', x    x= 2     print  ' changed local x to  ',  xx = 50func () print  ' Value  of x is ',  x4. Default parameter #!/usr/bin/env python#filename: fun_default.pydef saY (message, times = 1):     print message * timessay (' Hello ') Say (' World ',  5) 5. Key parameter #!/usr/bin/env python#filename: fun_key.pydef func (a, b=5,  c=10):    print  ' a is ', a,  ' and b is ', b,  ' and  c is ',  cfunc (3, 7) func (25, c=24) func (c=50, a=100) 6.return statement #!/usr/bin/env  Python# filename: fun_return.pydef maximum (x, y):    if x  > y:        return x    else:  Use of        return yprint maximum (2, 3) 7.DocStrings, Document string Note when calling with the. __doc__#!/usr/bin/env python# filename: fun_doc.pydef printmax (x, y):      ' prints the maximum of two numbers.     The two values mUst be integers. "     x = int (x)     y = int (y)      if x > y:        print x,  ' is  Maximum '     else:        print y,  ' is  maximun ' Printmax (3, 5) print printmax.__doc__


This article is from the "Notes" blog, so be sure to keep this source http://sunflower2.blog.51cto.com/8837503/1546258

Use of Python----functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.