随笔分类 -  python其他

python其他随笔
摘要:1、递归函数 函数内部自己调用自己,需要一个出口,避免陷入死循环 例如1: def num_list(first, end): """递归:打印first-end的值""" if first == end: print(end) else: print(first) first += 1 num_l 阅读全文
posted @ 2023-02-21 14:26 王枫子 阅读(20) 评论(0) 推荐(0)
摘要:1、使用索引反转字符串 str="hello" print(str[::-1]) 2、zip函数获取可迭代对象,将它们聚合到一个元组中,然后返回结果。语法是zip(*iterables) numbers = [1, 2, 3] string = ['one', 'two', 'three'] res 阅读全文
posted @ 2023-02-16 13:28 王枫子 阅读(67) 评论(0) 推荐(0)
摘要:python3数据类型包括: 数字、字符串str、列表list、元组tuple、字典dict、集合set、布尔bool 1、字符串(str)-可变-用""、''定义 (1)upper() 字母小写变大写 (2)swapcase() 字母大写变小写 (3)replace('a','b') 替换,a替换 阅读全文
posted @ 2023-02-15 22:43 王枫子 阅读(48) 评论(0) 推荐(0)