Learn python3 in one picture.

离线版思维导图

Local Picture

示例

字典

1
2
3
4
5
ls = {s: len(s) for s in ["Python", "Javascript", "Golang"]}
print(ls)

sl = {v: k for k, v in ls.items()}
print(sl)

装饰符

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
def log(f):
    def wrapper():
        print("Hey log~")
        f()
        print("Bye log~")
    return wrapper

@log
def fa():
    print("This is fa!")

# Equal to...
def fb():
    print("This is fb!")
fb = log(fb)

fa()
print("*"*10)
fb()

继承

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
class Animal:
    """This is an Animal"""
    def __init__(self, can_fly = False):
        self.can_fly = can_fly
    def fly(self):
        if self.can_fly:
            print("I CAN fly!")
        else:
            print("I can not fly!")
class Dog(Animal):
    """This is a Dog"""
    def bark(self):
        print("Woof!")
d = Dog()
d.fly()
d.bark()

来源