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个类中,函数可以随便引用

  • 相关阅读:
    04_特征工程
    03_特征清洗
    02_数据探索
    01_简介
    cache是什么文件?
    gulp详细入门教程
    HTML5实战与剖析之触摸事件(touchstart、touchmove和touchend)
    h4和h5的区别
    弹性盒布局
    js面向对象
  • 原文地址:https://www.cnblogs.com/merry-0131/p/8464805.html
Copyright © 2011-2022 走看看