正在加载图片...
中国科学技术大学电子工程与信息科学系 ©2020 写一段代码,允许输入3遍口令。 如果输入的口令是“abc”,显示“OK”,否则显示“wrong password,pls input again” 1.4函数(function) 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段。 你可以定义一个由自己想要功能的函数,以下是简单的规则: 函数代码块以def关键词开头,后接函数标识符名称和圆括号0。 任何传入参数和白变量必须放在圆括号中间。圆括号之间可以用于定义参数。 函数的第一行语句可以选择性地使用文档字符串一用于存放函数说明。 函数内容以冒号起始,并且缩进。 return表达式结束函数,选择性地返回一个值给调用方。不带表达式的return相 当于返回None。 1.4.1 自定义函数 仅用于 https:Iwww runoob com/python/python-functions 例如, def my_add(a,b): return a+b a=3 b=5 print(my_add(a,b)) 信息科学技术 1.4.2 Python内置函数 https://www.runoob.com/python/python-built-in-functions.html abs() divmod() input() open() staticmethod() all() enumerate() intO ordo str() any() eval() isinstance() pow( sum( basestring() execfile() issubclass() print() super() bin( file( iter() property() tuple() bool() filter len() range() type() bytearray() float() listo raw input() unichr() callable() format() locals() reduce() unicode() chro frozenset() long() reload() vars() classmethod() getattr() map() repr() xrange() cmp() globals() max() reverse() zip() compile() hasattr() memoryview() round() import ( complex( hash() min() set() delattr() help( next() setattr() dicto hex() object() slice) dir() idO oct() sorted() exec内置表达 network @ustc.edu.cn中国科学技术大学电子工程与信息科学系 ©2020 network@ustc.edu.cn 写一段代码,允许输入 3 遍口令。 如果输入的口令是“abc”,显示“OK”,否则显示“wrong password, pls input again” 1.4 函数(function) 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段。 你可以定义一个由自己想要功能的函数,以下是简单的规则:  函数代码块以 def 关键词开头,后接函数标识符名称和圆括号()。  任何传入参数和自变量必须放在圆括号中间。圆括号之间可以用于定义参数。  函数的第一行语句可以选择性地使用文档字符串—用于存放函数说明。  函数内容以冒号起始,并且缩进。  return [表达式] 结束函数,选择性地返回一个值给调用方。不带表达式的 return 相 当于返回 None。 1.4.1 自定义函数 参考 https://www.runoob.com/python/python-functions.html 例如, def my_add(a,b): return a + b a = 3 b = 5 print(my_add(a,b)) 1.4.2 Python 内置函数 https://www.runoob.com/python/python-built-in-functions.html abs() divmod() input() open() staticmethod() all() enumerate() int() ord() str() any() eval() isinstance() pow() sum() basestring() execfile() issubclass() print() super() bin() file() iter() property() tuple() bool() filter() len() range() type() bytearray() float() list() raw_input() unichr() callable() format() locals() reduce() unicode() chr() frozenset() long() reload() vars() classmethod() getattr() map() repr() xrange() cmp() globals() max() reverse() zip() compile() hasattr() memoryview() round() __import__() complex() hash() min() set() delattr() help() next() setattr() dict() hex() object() slice() dir() id() oct() sorted() exec 内 置 表 达
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有