Python function notes

Source: Internet
Author: User

function return value
#coding: Utf-8
def f (x, Y):
Print x+y/*x+y is calculated x+y If "x+y" is directly output x+y*/
F (97,98)
D:\Python installation program \python.exe c:/users/Huan/pycharmprojects/untitled/ll.py
195

Process finished with exit code 0
#coding: Utf-8
def f (x, Y):
Print "Welcome"
Print X+y
F (2,3)
Z=f (3,4)
Print Z
D:\Python installation program \python.exe c:/users/Huan/pycharmprojects/untitled/ll.py
Welcome
5
Welcome
7
None

Process finished with exit code 0
#coding: Utf-8
def f ():
return "Hello"
z= f ()/* must return a specified value after the function is called, otherwise it cannot output */
Print Z
D:\Python installation program \python.exe c:/users/Huan/pycharmprojects/untitled/ll.py
Hello

Process finished with exit code 0
#coding: Utf-8
def f ():
    return "Hello"/* Enter two return at a time, Only the first execution is the return execution after the function terminates */
    return "RR"
z= f ()
Print z
D:\Python setup \python.exe c:/users /Huanhuan/pycharmprojects/untitled/ll.py
Hello
Process finished with exit code 0
Transfer tuples and dictionaries to functions
#coding: Utf-8
t= (' name ', ' Milo ')
def f (x, y):
    print "% s:% s"% (x, y)/* Note this notation */
F (*t) /* Two values for output T-tuple */
D:\Python installer \python.exe c:/users//pycharmprojects/untitled/ll.py
 name:milo

Process finished with exit code 0
#coding: Utf-8
def f (name= ' name ', age=0):
    print "name:%s"% name
    print "Age:%d"% age
F ("Milo", "9")
d={"name": ' Milo ', "Age": 20}/* Dictionary of Disorder */
F (**d)/* Defines method of dictionary invocation */
d={' a ':, ' n ': ' Milo '}
F (d [' N '],d[' a '])//* Two values to correspond */
D:\Python installer \python.exe c:/users//pycharmprojects/untitled/ll.py
Name:milo
age:30
Name:milo
age:20
Name:milo
age:9
Processing redundant real numbers
#coding: Utf-8
def f (x,*args):
    print x
    print args
F (
style= "color: #ff0000;" >def F (x,* Args,**kwargs):/* A * represents a tuple, two * * denotes dictionary */
    print x
    print args
    print Kwargs
F (x=1,y=3,z=4)/*y=3,z=4 root tuple form */
D:\Python installer \python.exe c:/users/Huan/ pycharmprojects/untitled/ll.py
1
(2, 3)
1
()
{' Y ': 3, ' Z ': 4}

Process finished with exit code 0
Process finished with exit code 0

Python function notes

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.