美文网首页
python基础-函数

python基础-函数

作者: feitry | 来源:发表于2018-12-28 19:02 被阅读0次

定义函数格式:
def 函数名称(参数 = None):
代码组
其中 参数 = None ,设置默认值可为空

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

def printHelloWithName(name):
    print('hello world! ',name)

def printHell0WithTime(time=None):
    print('hello world ! -',time)

def printStudent(name , age):
    print('name: ', name , 'age: ', age)

def printMyFridend(name = '' , age = 0):
    print("My friden is ",name,' age is ',age)
    return "hah"
printHello()
printHelloWithName("Lily")
printHelloWithName("")

printHell0WithTime("今天")
printHell0WithTime()

printStudent('Lily',12)
printStudent('Lily','14 years old')
printMyFridend('Lucy',12)
printMyFridend('Lucy','13 years old')

相关文章

  • python基础笔记

    Python基础 函数:

  • Python入门

    Python3教程 安装Python 第一个Python程序 Python基础 函数 高级特性 函数式编程 模块 ...

  • python入门套路

    Python基础 基础数据类型 bool string list tuple dictionary 基础函数 he...

  • python基础-07-函数

    python基础-函数 1.函数的定义 例子: 2.python中函数的参数详解 必备参数demo: 默认参数de...

  • Python基础-函数

    Python基础-函数 1.函数定义 2.参数传值 3.内置函数

  • 理解Python中的闭包

    Python基础 在Python中,函数也是一个对象,而且函数对象可以被赋值给变量,所以,通过变量也能调用该函数。...

  • Python基础 - 函数基础

    知识回顾 列表,字典,元组,集合 列表(list):[];可变,有序;元素是任何类型的数据增:append,ins...

  • Python从入门到精通

    Python语法的三个阶段 Python基础语法函数是编程 Python进阶语法面向对象编程 Python高级语法...

  • #python基础入门#目录

    python基础入门_01 保留字常用函数turtle库基本数据类型time库 python基础入门_02 程序的...

  • 2018-07-25Python(7)

    python基础语法(7) 函数下 lambda函数lambda函数有自己的作用域。代码示例:def makeAc...

网友评论

      本文标题:python基础-函数

      本文链接:https://www.haomeiwen.com/subject/dsmelqtx.html