python函数总结(python 函数中的函数)

python函数总结(python 函数中的函数)TRAVEL 点击蓝字 关注我们 小伙伴们 大家好呀 今天我们学习关于 Python 的 二十个函数 让我们一起来学习吧 nbsp nbsp 1 print nbsp nbsp 打印输出内容到控制台 print hello world nbsp nbsp 2 len nbsp

大家好,我是讯享网,很高兴认识大家。



TRAVEL

点击蓝字 关注我们


讯享网

小伙伴们,大家好呀!

今天我们学习关于Python的

二十个函数

print(“hello,world!”)

讯享网

   2. len()     - 返回序列对象的长度

讯享网fruits = [“apple”,“banana”,“cherry”] print(len(fruits)) #输出:3

   3. input()   - 从用户获取输入

name = input(“请输入您的名字:”)print(“您好,” + name)

   4. str()      - 将对象转换为字符串

讯享网number = 10print(“The number is:” + str(number))

   5. int()      - 将对象转换为整数

age = int(input(“请输入您的年龄:”)) print(“您的年龄是:”+ str(age))

   6. float()    -将对象转换为浮点数

讯享网pi = float(“3.14”) print(pi)

   7. range()   - 返回指定范围的整数序列

numbers = list(range(1,6))print(numbers) # 输出:[1,2,3,4,5]

   8. max()      - 返回最大值

讯享网numbers = [5,10,3,8]print(max(numbers)) # 输出:10

   9. min()       - 返回最小值

numbers = [5,10,3,8]print(min(numbers)) # 输出:3

   10. sum()      - 返回序列对象中元素的总和

讯享网numbers = [1,2,3,4,5]print(sum(numbers)) #输出:15

   11. abs()          - 返回一个数的绝对值

print(abs(-10)) # 输出:10

   12. round()        - 四舍五入取整

讯享网print(round(3.1415,2))# 输出:3.14

   13. sorted()      - 对序列对象进行排序

numbers = [5,2,8,3,1]print(sorted(numbers)) # 输出:[1,2,3,5,8]

   14. type()          - 返回对象的类型

讯享网print(type(“Hello”)) # 输出:<class ‘str’>

   15. str.upper()    - 将字符串转换为大写

text = “hello”print(text.upper()) # 输出:HELLO

   16. str.lower()    - 将字符串转换为小写

讯享网text = “WORLD”print(text.lower()) # 输出:world

   17. str.capitalize()    -将字符串的首字母大写

text = “hello world”print(text.capitalize()) # 输出: Hello world

   18. str.split()     - 将字符串以空格分割为列表

讯享网text = “hello world”print(text.split()) # 输出:[‘hello’, ‘world’ ]

   19. str.replace()    - 替换字符串中的指定字符

text = “hello world”print(text.replace(“world”,“Python”)) # 输出:hell

   20. list.append()    - 向列表末尾添加元素

讯享网fruits = [“apple”,“banana”] fruits.append(“cherry”)print(fruits) # 输出:[‘apple’, ‘banana’, ‘cherry’ ]

END

本期的学习就到这里啦

关于Python的函数还有很多

感兴趣的同学可以自己在网上学习

   

图文|陈韵儿
排版|陈韵儿
初审|萧均榆
复审|罗阳倩子
黄国杰
终审|黄   生

小讯
上一篇 2025-04-19 08:49
下一篇 2025-06-08 07:27

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/152947.html