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_\345\230\230\345\230\230/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/.keep" "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_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/.keep" similarity index 100% rename from "\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_\345\230\230\345\230\230/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/.keep" rename to "\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_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/.keep" 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_\345\230\230\345\230\230/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_12.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_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_12.py" similarity index 95% rename from "\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_\345\230\230\345\230\230/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_12.py" rename to "\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_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_12.py" index 18fcb3889b444a47e5c04f0273c984e3cb1843db..dbb32c56b8aadee05299d2d2c1e9b7d28e5de8d0 100644 --- "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_\345\230\230\345\230\230/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_12.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_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_12.py" @@ -1,40 +1,40 @@ -from threading import Thread -import time -from multiprocessing import process - -#第一问,实现一个多线程程序 -def one(num): - for i in range(num): - print(f"I am {i}") - time.sleep(0.5) - -def two(num): - for i in range(num): - print(f"you are {i}") - time.sleep(0.5) - -def main(): - t_one = Thread (target = one, args = (5, )) - t_two = Thread (target = two, args = (6, )) - t_one.start() - t_two.start() - -if __name__ == '__main__': - main() - -#第二部,将多线程改为多进程 -def one(num): - for i in range(num): - print(f"I am {i}") - - -def two(num): - for i in range(num): - print(f"you are {i}") - - -def main(): - p_one = process (target = one, args = (5, )) - p_two = process(target = two, args = (6, )) - p_one.start() +from threading import Thread +import time +from multiprocessing import process + +#第一问,实现一个多线程程序 +def one(num): + for i in range(num): + print(f"I am {i}") + time.sleep(0.5) + +def two(num): + for i in range(num): + print(f"you are {i}") + time.sleep(0.5) + +def main(): + t_one = Thread (target = one, args = (5, )) + t_two = Thread (target = two, args = (6, )) + t_one.start() + t_two.start() + +if __name__ == '__main__': + main() + +#第二部,将多线程改为多进程 +def one(num): + for i in range(num): + print(f"I am {i}") + + +def two(num): + for i in range(num): + print(f"you are {i}") + + +def main(): + p_one = process (target = one, args = (5, )) + p_two = process(target = two, args = (6, )) + p_one.start() p_two.start() \ 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_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_14.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_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_14.py" new file mode 100644 index 0000000000000000000000000000000000000000..5ac8228cebf0d20b921ddb4ecd1f044d68abb791 --- /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_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_14.py" @@ -0,0 +1,57 @@ +from threading import Thread, Lock +import time +from multiprocessing import Process, Lock, Queue + +#第一问 +#多进程锁 +def one(num, lock): + with lock: + for i in range(num): + print(f"I am {i}") + + + +def main(): + lock = Lock() + t_one = Process (target = one, args = (5, lock)) + t_one.start() + +if __name__ == '__main__': + main() + +#多线程锁 +a = 0 +lock = Lock() +def two(): + global a + for i in range(10**3): + with lock: + a += 1 + a -= 1 + + + +def main(): + t_two = Thread (target = two) + t_two.start() + print(a) + +if __name__ == '__main__': + main() + +#第二问,把进程通过Queue来实现进程通信 +def three(num, my_queue): + my_queue. put(num) + +if __name__ == '__main__': + my_queue = Queue() + for i in range(10): + p_three = Process (target = three, args = (i, my_queue)) + p_three.start() + + while True: + print(my_queue.get()) + + + + 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_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/21.01.05.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_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21.01.05.py" similarity index 100% rename from "\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_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/21.01.05.py" rename to "\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_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21.01.05.py" 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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/.keep" "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_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/.keep" similarity index 100% rename from "\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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/.keep" rename to "\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_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/.keep" 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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_09.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_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_09.py" similarity index 94% rename from "\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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_09.py" rename to "\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_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_09.py" index a276c066a0f726d4c8ca3920ca6b3194b15c5186..cd12e4945824865d357de7d259758657d28e0c0c 100644 --- "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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_09.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_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_09.py" @@ -1,48 +1,48 @@ -#第一问 -class MyMath: - @staticmethod - def add(a, b): - return a + b - - def sub(a, b): - return a - b - - def mul(a, b): - return a * b - - def div(a, b): - return a / b - - def ediv(a, b): - return a // b - - def rem(a, b): - return a % b - - def sqrt(a, b): - return float(a ** (1 / 2)) - -print(MyMath.ediv(10,5)) - -#第二问 -class Cat: - cute_cat = True - __mycat = {"David": 2} - def __init__(self, name, age): - - self. name = name - self. __age = age - - @classmethod - def __new__(cls, *args, **kwargs): - print("猫咪真可爱") - return super().__new__(cls) - - def __str__(self): - return "名字是:%s , 年龄是:%d" % (self. name, self. __age) - - - -print(Cat. _Cat__mycat) -tom = Cat("汤姆", 30) +#第一问 +class MyMath: + @staticmethod + def add(a, b): + return a + b + + def sub(a, b): + return a - b + + def mul(a, b): + return a * b + + def div(a, b): + return a / b + + def ediv(a, b): + return a // b + + def rem(a, b): + return a % b + + def sqrt(a, b): + return float(a ** (1 / 2)) + +print(MyMath.ediv(10,5)) + +#第二问 +class Cat: + cute_cat = True + __mycat = {"David": 2} + def __init__(self, name, age): + + self. name = name + self. __age = age + + @classmethod + def __new__(cls, *args, **kwargs): + print("猫咪真可爱") + return super().__new__(cls) + + def __str__(self): + return "名字是:%s , 年龄是:%d" % (self. name, self. __age) + + + +print(Cat. _Cat__mycat) +tom = Cat("汤姆", 30) print(tom) \ 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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/.keep" "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_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/.keep" similarity index 100% rename from "\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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/.keep" rename to "\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_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/.keep" 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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_07.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_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_07.py" similarity index 95% rename from "\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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_07.py" rename to "\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_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_07.py" index f0938caa4905eab6d3b1622e4d14072d58ce9392..dfc2695040e628e91f5123b7b1ce84a473ed5d4b 100644 --- "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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_07.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_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_07.py" @@ -1,76 +1,76 @@ -#第一问,用类封装一个MyMath类 -class MyMath: - def add(self, a, b): - return a + b - - def sub(self, a, b): - return a - b - - def mul(self, a, b): - return a * b - - def div(self, a, b): - return a / b - - def ediv(self, a, b): - return a // b - - def rem(self, a, b): - return a % b - - def sqrt(self, a, b): - return float(a ** (1 / 2)) -a = MyMath() -a. add(10, 5) -print(a) - -# 定义类 -#第一个 -class Cat: - def __init__(self, a, b): - self. name = a - self. age = b - - def __str__(self): - return "名字是:%s , 年龄是:%d" % (self. name, self. age) - - def eat(self): - print(f"{self. name}在吃鱼") - - def drink(self): - print(f"{self. name}在喝牛奶") - -tom = Cat("汤姆", 30) -a = Cat("David", 20) -a. eat() - -#第二个 -class MyClass: - countnum = 0 - def __init__(self, name, age): - self. name = name - self. age = age - MyClass. countnum += 1 - - def totalnum(self): - print("总人数为:", MyClass. countnum) - - def displaystudent(self): - print("名字:", self. name, " ", "年龄:", self. age) - - -#第三问,创建相应子类 -class firstchild(MyClass): - def great(self): - print(f"{self. name}是大神") - -class secondchild(MyClass): - def good(self): - print(f"我们都得向{self. name}看齐!") - -A = firstchild("小天", 20) -B = secondchild("小天", 20) -A. great() -B. good() -print(A) -print(B) +#第一问,用类封装一个MyMath类 +class MyMath: + def add(self, a, b): + return a + b + + def sub(self, a, b): + return a - b + + def mul(self, a, b): + return a * b + + def div(self, a, b): + return a / b + + def ediv(self, a, b): + return a // b + + def rem(self, a, b): + return a % b + + def sqrt(self, a, b): + return float(a ** (1 / 2)) +a = MyMath() +a. add(10, 5) +print(a) + +# 定义类 +#第一个 +class Cat: + def __init__(self, a, b): + self. name = a + self. age = b + + def __str__(self): + return "名字是:%s , 年龄是:%d" % (self. name, self. age) + + def eat(self): + print(f"{self. name}在吃鱼") + + def drink(self): + print(f"{self. name}在喝牛奶") + +tom = Cat("汤姆", 30) +a = Cat("David", 20) +a. eat() + +#第二个 +class MyClass: + countnum = 0 + def __init__(self, name, age): + self. name = name + self. age = age + MyClass. countnum += 1 + + def totalnum(self): + print("总人数为:", MyClass. countnum) + + def displaystudent(self): + print("名字:", self. name, " ", "年龄:", self. age) + + +#第三问,创建相应子类 +class firstchild(MyClass): + def great(self): + print(f"{self. name}是大神") + +class secondchild(MyClass): + def good(self): + print(f"我们都得向{self. name}看齐!") + +A = firstchild("小天", 20) +B = secondchild("小天", 20) +A. great() +B. good() +print(A) +print(B)