随笔分类 -  python

摘要:1.可存在同名对象 class A: def __init__(self): print('this is class.') def A(): print('this is method.') a = A() # this is method. 由于python是边编译边执行的语言,所以只会使用最近 阅读全文
posted @ 2022-10-14 17:07 Bridgebug 阅读(151) 评论(0) 推荐(0)
摘要:一、创建类 class People: pass p = People() 二、构造函数 __init__()方法是一种特殊的方法,被称为类的构造函数或初始化方法,当创建了这个类的实例时就会调用该方法。 python中一个类只能有一个构造函数,即只能有一个 __init__ 方法(有多个时,最后一个 阅读全文
posted @ 2022-10-14 16:52 Bridgebug 阅读(83) 评论(0) 推荐(0)
摘要:假如有脚本 test1.py def get(): return 'this is test1' 在脚本 test2.py 中调用 test1.py 的 get 方法 1.用全名访问 import test1 print(test1.get()) 2.用别名访问 import test1 as t1 阅读全文
posted @ 2022-07-28 15:31 Bridgebug 阅读(132) 评论(0) 推荐(0)
摘要:1.函数修饰符(@) @与其说是修饰不如说其是引用 def use(f): def test(): print('this is use test') f() return test @use def usetest(): print('Hello') usetest() # 输出: # this 阅读全文
posted @ 2022-04-12 22:45 Bridgebug 阅读(105) 评论(0) 推荐(0)
摘要:时间间隔是以秒为单位的浮点小数。每个时间戳都以自从1970 年 1 月 1 日午夜(历元)经过了多长时间来表示。 import time ticks = time.time() print (f"当前时间戳为:{ticks}秒") # 当前时间戳为: 1649243762.6342976秒 时间戳单 阅读全文
posted @ 2022-04-12 22:45 Bridgebug 阅读(121) 评论(0) 推荐(0)