diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/.keep" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/.keep" deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232.py" new file mode 100644 index 0000000000000000000000000000000000000000..cef104d893cdc64f272da7f97b0c89b59066833e --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232.py" @@ -0,0 +1,23 @@ +def fib1(num): + results = [0, 1] + for i in range(num): + result = results[0] + results[1] + results[0] = results[1] + results[1] = result + return results[1] + + +def fib2(num): + results = [0, 1] + i = 0 + while i < num: + result = results[0] + results[1] + results[0] = results[1] + results[1] = result + i = i + 1 + return results[1] + + +if __name__ == '__main__': + print(fib1(100)) + print(fib2(100)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.py" new file mode 100644 index 0000000000000000000000000000000000000000..6bba3d9b7a05fc01f7390c875c782b66c65f1c1c --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.py" @@ -0,0 +1,44 @@ +from datetime import datetime + + +def print_time(func): + def wrapper(): + print("Run time: {}".format(datetime.now())) + return func() + + return wrapper + + +@print_time +def foo(): + print("I am foo") + + +foo() + + +def cache(func): + _cached = {} + + def wrapper(n): + if n in _cached: + return _cached[n] + else: + result = func(n) + _cached[n] = result + return result + + return wrapper + + +@cache +def fib(n): + if n == 1: + return 1 + if n == 2: + return 1 + + return fib(n-2) + fib(n-1) + + +print(fib(100)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232.py" new file mode 100644 index 0000000000000000000000000000000000000000..b8c84fec9b7ffe652f455765005cb53780886a7f --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232.py" @@ -0,0 +1,41 @@ +classes = [ + {"name": "n_1", "age": 24, "grade": "A"}, + {"name": "n_2", "age": 23, "grade": "B"}, + {"name": "n_3", "age": 28, "grade": "A"}, + {"name": "n_4", "age": 24, "grade": "A"}, + {"name": "n_5", "age": 25, "grade": "C"}, + {"name": "n_6", "age": 21, "grade": "D"}, + {"name": "n_7", "age": 27, "grade": "A"}, +] + + +def choose_grade(item): + return item['grade'] == 'A' + + +grade_a_list = filter(choose_grade, classes) +for i in grade_a_list: + print(i) + + +def add_age(item): + item["age"] = item["age"] + 1 + return item + + +new_classes = map(add_age, classes) + + +for i in new_classes: + print(i) + + +def fib(n): + if n == 1: + return 1 + if n == 2: + return 1 + return fib(n-1) + fib(n-2) + + +print(fib(10)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232.py" new file mode 100644 index 0000000000000000000000000000000000000000..dc2ad7d791ea24f015e0317cedc46a38f73fc1e9 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232.py" @@ -0,0 +1,15 @@ +import datetime + +now = datetime.datetime.now() +print(now.timestamp()) +print(now.strftime("%Y-%m-%d %H:%M:%S")) + + +def get_date(day_delta): + base_date = datetime.datetime(2021, 1, 3) + target_date = base_date + datetime.timedelta(days=day_delta) + return target_date.strftime("%Y-%m-%d") + + +print(get_date(-1)) +print(get_date(1)) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.py" new file mode 100644 index 0000000000000000000000000000000000000000..e871264ea5c7c37e555600b06b63fd6997306ac7 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.py" @@ -0,0 +1,63 @@ +class MyMath: + @classmethod + def add(cls, a, b): + return a + b + + @classmethod + def minus(cls, a, b): + return a - b + + @classmethod + def multi(cls, a, b): + return a * b + + @classmethod + def div(cls, a, b): + return a / b + + @classmethod + def pow(cls, a, b): + return a ** b + + @classmethod + def sqrt(cls, a): + return a ** 0.5 + + +print(MyMath.add(1, 2)) +print(MyMath.minus(1, 2)) +print(MyMath.multi(1, 2)) +print(MyMath.div(1, 2)) +print(MyMath.pow(3, 2)) +print(MyMath.sqrt(2)) + + +class Person: + prop = 'Person Property' + __prop = 'Private Person Property' + + def __init__(self, name, age): + self.__name = name + self.__age = age + + @classmethod + def print_props(cls): + print('Prop: {}, Private Prop: {}'.format(cls.prop, cls.__prop)) + + def __str__(self): + return ''.format(self.__name, self.__age) + + +class Student(Person): + def __init__(self, name, age, class_no): + super().__init__(name, age) + self.__class_no = class_no + + +Person.print_props() + +mike = Student('Mike', 23, 1) +jame = Student('Jame', 22, 2) + +print(mike) +print(jame) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232.py" new file mode 100644 index 0000000000000000000000000000000000000000..fb037a142bc8dac3eaa87591e7880cb536ce4c72 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232.py" @@ -0,0 +1,49 @@ +class MyMath: + def add(self, a, b): + return a + b + + def minus(self, a, b): + return a - b + + def multi(self, a, b): + return a * b + + def div(self, a, b): + return a / b + + def pow(self, a, b): + return a ** b + + def sqrt(self, a): + return a ** 0.5 + + +my_math = MyMath() +print(my_math.add(1, 2)) +print(my_math.minus(1, 2)) +print(my_math.multi(1, 2)) +print(my_math.div(1, 2)) +print(my_math.pow(3, 2)) +print(my_math.sqrt(2)) + + +class Person: + def __init__(self, name, age): + self.name = name + self.age = age + + def introduce(self): + print('My name is {}, my age is {}'.format(self.name, self.age)) + + +class Student(Person): + def __init__(self, name, age, class_no): + super().__init__(name, age) + self.class_no = class_no + + +mike = Student('Mike', 23, 1) +jame = Student('Jame', 22, 2) + +mike.introduce() +jame.introduce() \ No newline at end of file