Python中如何定义一个函数
定义函数的格式是: def functionName(arg):
例如:定义一个输出Fibonacci序列的函数
def fibonacci(n):
a, b = 0, 1
while b < n:
print(b, end=’ ‘)
a, b = b, a+b
print()
fibonacci(100)
例如:定义一个输出Fibonacci序列的函数
def fibonacci(n):
a, b = 0, 1
while b < n:
print(b, end=’ ‘)
a, b = b, a+b
print()
fibonacci(100)
【Python中如何定义一个函数】相关文章
8. Ruby如何定义一个类
10. Python里面如何拷贝一个对象
本文来源:https://www.mianshiwenti.com/a13492.html
进入下载页面
上一篇:介绍一下except的用法和作用
下一篇:Python里面如何拷贝一个对象
﹝Python中如何定义一个函数﹞相关内容
- 如何用Python来进行查询和替换一个文本字符串
- 如何用Python输出一个Fibonacci数列
- 写一个函数,求一个字符串的长度。在main函数中输入字符串,并输出其长度
- 请写出一段Python代码实现删除一个list里面的重复元素
- 用Python写一个for循环的例子
- 请用Python写一个获取用户输入数字,并根据数字大小输出不同信息的脚本
- 软件测试LoadRunner面试题:What is think time? How do you change the threshold?
- 写一个函数,要求输入一个字符串和一个字符长度,对该字符串进行分隔
- Python是如何进行类型转换的
- Python里面如何实现tuple和list的转换