zoukankan      html  css  js  c++  java
  • 第 017讲:函数:Python的乐高积木

    1. 

    >>> def myfuction(mun1,mun2):
    result = mun1 + mun2
    print(result)

    >>> myfuction(1,2)
    3
    >>>

    课后作业:

    1. 没有听说过DRY

    2.函数可以变量

    3. 创建函数,使用关键字的时候需要明确关键字是干什么作用的,定义好

    4. 

    def MyFun((x, y), (a, b)):
    return x * y - a * b

    这个函数有多少个参数, 四个参数

     答案: 0个

    5. 

    >>> def hello():
    print('hello world')
    return
    print('welcome to fish.com!')


    >>> hello()
    hello world
    >>>

    动动手答案:

    def power(x, y):
    result = 1

    for i in range(y):
    result *= x

    return result

    print(power(2, 3))

    def gcd(x, y):
    while y:
    t = x % y
    x = y
    y = t

    return x

    print(gcd(4, 6))

  • 相关阅读:
    COM组件
    【游戏引擎架构】入门(一)
    UNICODE字符串
    Python随笔10
    Python随笔9-函数
    Python随笔7
    Python随笔6
    Python随笔5
    Python随笔4
    Python随笔3
  • 原文地址:https://www.cnblogs.com/jiangkeji/p/9086850.html
Copyright © 2011-2022 走看看