python3 基础笔记 03

1. 临时笔记

# 1.ubuntu命令行启动wps文字, 直接就是 wps
# "et", "WPS表格程序","wpp"  "WPS演示程序"。

# 2.主要是看看 assert 的语法。
# print("ok")

# assert hasattr(requests, 'get'), "here is a example of debug!"
# assert hasattr(requests, 'getMyAss'), "You little piece of shit!!"

# print(3+2)    # 如果上面的断言出错了。这行不会执行的。

2.其他笔记


# 1.__call__, 这个dunder方法,免去了方法名称的调用。
class Adder:
    def add(self, x, y):
        return x+y

    def __call__(self, x, y):
        return x*y

a = Adder()


# 可以这样调用:
# a.add(2, 3)   # 5
# a(4, 5)       # 20

# 2.迭代器。不仅返回一个值,而且交出了控制权。
def compute():
    for i in range(10):
        sleep(.5)
        yield i 

for x in compute():
    print(x)


你可能感兴趣的:(python3 基础笔记 03)