zoukankan      html  css  js  c++  java
  • Python函数,参数,变量

    func1.py

    def sayHello():
        print ('hello world')
    sayHello()
    

    func_parm.py

    def printMax(a,b):
        if a>b:
            print (a,'is maximum')
        else:
            print (b,'is maximum')
    printMax(3,4)
    x=5
    y=7
    printMax(x,y)
    

    func_local.py

    def func(x):
        print ('x is',x)
        x=2
        print ('changed local x to',x)
    x=50
    func(x)
    print ('x is still',x)
    

    func_global.py

    def func():
        global x
        print ('x is',x)
        x=2
        print ('changed local x to',x)
    x=50
    func()
    print ('Value of x is ',x)
    

    func_default.py

    def say(message,times=1):
        print (message*times)
    
    say('Hello')
    say('Wolrd',5)
    

    func_key.py

    def func(a,b=5,c=10):
        print ('a is ',a, 'and b is', b, 'and c is', c)
    func(3,7)
    func(25,c=24)
    func(c=50,a=100)
    

    func_return.py

    def maximum(x,y):
        if x>y:
            return x
        else:
            return y
    print(maximum(2,3))
    

    func_doc.py

    def printMax(x, y):
        '''Prints the maximum of two numbers. The two values must be integers.'''
        x = int(x) # convert to integers, if possible
        y = int(y)
        if x > y:
            print (x, 'is maximum')
        else:
            print (y, 'is maximum')
    printMax(3, 5)
    print (printMax.__doc__)
    
  • 相关阅读:
    读《见识》 | 当别人扇了你一巴掌
    Java集合类
    Java数据结构简述
    Java加密算法
    Java JDK与JRE
    Java String、StringBuilder、StringBuffer[笔记]
    Java同步(Synchronization)
    Java断言(Assertion)
    Java strictfp
    Java Native Interface(JNI)
  • 原文地址:https://www.cnblogs.com/oskb/p/5066195.html
Copyright © 2011-2022 走看看