2025年12月26日

python range()函数

摘要: python3 range()生成一个迭代对象 1 def test_range(): 2 range_res = range(0, 5, 1) 3 return range_res 4 5 6 if __name__ == '__main__': 7 res = test_range() 8 fo 阅读全文

posted @ 2025-12-26 21:45 luckygxf 阅读(4) 评论(0) 推荐(0)

python @args @kwargs使用

摘要: 1 def func(argument, *args, **kwargs): 2 print(argument) 3 print(args) 4 print(kwargs) 5 6 7 if __name__ == '__main__': 8 func(1, 2, a='zhangsan') 阅读全文

posted @ 2025-12-26 00:31 luckygxf 阅读(1) 评论(0) 推荐(0)

python @wrap装饰器保留原函数__name__和__doc__属性

摘要: 不使用@wrap装饰器 def print_log(fn): def wrap(*args, **kwargs): ''' 这是包装函数 :param args: :param kwargs: :return: ''' print("before execute function") result 阅读全文

posted @ 2025-12-26 00:23 luckygxf 阅读(5) 评论(0) 推荐(0)

python with使用

摘要: 使用with 打开文件,不用手动关闭文件。自动关闭文件 def read_file(file_path: str): with open(file_path, 'r', encoding='utf-8') as file: content = file.read() print(content) d 阅读全文

posted @ 2025-12-26 00:06 luckygxf 阅读(4) 评论(0) 推荐(0)

导航