zoukankan      html  css  js  c++  java
  • 简单的函数(也叫方法)

    1、脚本

    def max(a,b,c):
    x = a
    if (a<b): x=b
    if (b<c): x=c
    print ("the max num is %d" %x)

    def hello(list):
    list.append([1,2,3,4])
    print(list)
    return

    list = [10,11,12]
    hello(list)

    max(1,2,3)

    2、执行结果

    3、备注

    (1)函数以def开头;

             函数名括号中,可以有参数,也可以没有参数;

             函数名后边加冒号

             函数内容需要注意前边有4个空格的缩进量

    (2)Python中if条件后边加冒号:

    (3)Python List append()方法

    append() 方法用于在列表末尾添加新的对象
    append()方法语法:list.append(obj);obj为添加到列表末尾的对象。该方法无返回值,但是会修改原来的列表
    如:脚本中,将[1,2,3,4]添加到[10,11,12]后边

    (4)函数的引用

    1个类中,函数可以随便引用

  • 相关阅读:
    gems gems gems
    poj 6206 Apple
    lightoj1341唯一分解定理
    lightoj1370欧拉函数
    约瑟夫环lightoj1179
    拓展欧几里得算法
    RMQ算法
    poj1502MPI Maelstrom
    poj1860Currency Exchange
    生成全排列
  • 原文地址:https://www.cnblogs.com/merry-0131/p/8464805.html
Copyright © 2011-2022 走看看