range(10, 0, -1) # [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
print('Hao123'.isdigit()) # 所有字符都是数字吗?
digit :(从 0 到 9 的任何一个) 数字
print('hello.tar.gz'.split('.')) #分离 以·为分割标志 =>['hello', 'tar', 'gz']
print('.'.join(['hello','tar','gz'])) #合并 是split和join是相反的
# "%s is %d years old" % ('bob', 23) # 常用
# "%s is %d years old" % ('bob', 23.5) # %d是整数 常用
# "%s is %f years old" % ('bob', 23.5)
# a = "{} is {} years old".format('bob', 25)
# b ="{1} is {0} years old".format(25, 'bob')
- 记得学习下,python对文件操作

本文深入探讨了Python中range函数的使用,字符串方法如isdigit、split和join的应用,以及字符串格式化技巧,包括传统百分号格式化和format方法。通过具体示例,读者将掌握这些基础但关键的Python语法知识点。
1万+

被折叠的 条评论
为什么被折叠?



