diff --git a/.gitignore b/.gitignore index 17e2e83..4a04817 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ # Ignore 圆圆的py folder -圆圆的py/ +# 圆圆的py/ # Ignore .idea folder .idea/ +venv/ # Config by user test.py diff --git "a/\345\234\206\345\234\206\347\232\204py/1.py" "b/\345\234\206\345\234\206\347\232\204py/1.py" new file mode 100644 index 0000000..ecfba62 --- /dev/null +++ "b/\345\234\206\345\234\206\347\232\204py/1.py" @@ -0,0 +1,16 @@ +''' +@Description: +@LastEditors: liukai +@Date: 2020-05-08 21:12:49 +@LastEditTime: 2020-05-08 21:26:33 +@FilePath: /pyFile/1.py +''' + +# r = 3 +r = float(input('r = ')) +print(r) + +print(2 * 3.14 * r) + +# print("我是一行文本", a) +# print('hello', 'python', sep=',', end='!\n') # sep是自动在元素之间补充的分隔字符 \ No newline at end of file diff --git "a/\345\234\206\345\234\206\347\232\204py/2.py" "b/\345\234\206\345\234\206\347\232\204py/2.py" new file mode 100644 index 0000000..d89e019 --- /dev/null +++ "b/\345\234\206\345\234\206\347\232\204py/2.py" @@ -0,0 +1,20 @@ +''' +@Description: +@LastEditors: liukai +@Date: 2020-05-08 21:54:57 +@LastEditTime: 2020-05-09 10:08:11 +@FilePath: /pyFile/2.py +''' + +# sum = 0 +# for x in range(10): +# sum += x +# print(sum) + +sum = 0 +num = 1 +while num < 10: + sum += num + num += 1 + # num ++ # python不能 num ++ +print(sum) \ No newline at end of file diff --git "a/\345\234\206\345\234\206\347\232\204py/dict.py" "b/\345\234\206\345\234\206\347\232\204py/dict.py" new file mode 100644 index 0000000..6f2982f --- /dev/null +++ "b/\345\234\206\345\234\206\347\232\204py/dict.py" @@ -0,0 +1,27 @@ +''' +@Description: +@LastEditors: liukai +@Date: 2020-05-15 20:52:51 +@LastEditTime: 2020-05-15 21:03:06 +@FilePath: /pyFile/圆圆的py/dict.py +''' + +name_dict = {} +while True: + info_list = [] + name = input("姓名:") + if name == "": + break + else: + num = int(input("学号:")) + info_list.append(num) + score = float(input("成绩:")) + info_list.append(score) + name_dict[name] = info_list + +for key in name_dict: + print("姓名:%s 学号: %s 成绩: %.1f" % (key, name_dict[key][0], name_dict[key][1])) + +find = input("输入查找姓名") +if find in name_dict: + print("姓名:%s 学号: %s 成绩: %.1f" % (find, name_dict[find][0], name_dict[find][1])) diff --git "a/\345\234\206\345\234\206\347\232\204py/input.txt" "b/\345\234\206\345\234\206\347\232\204py/input.txt" new file mode 100644 index 0000000..795e934 --- /dev/null +++ "b/\345\234\206\345\234\206\347\232\204py/input.txt" @@ -0,0 +1,10 @@ +1 1 1 1 +2 2 2 2 +3 3 3 3 +4 4 4 4 +5 5 5 5 +6 6 6 6 +7 7 7 7 +8 8 8 8 +9 9 9 9 +10 10 10 10 \ No newline at end of file diff --git "a/\345\234\206\345\234\206\347\232\204py/list.py" "b/\345\234\206\345\234\206\347\232\204py/list.py" new file mode 100644 index 0000000..90b07c6 --- /dev/null +++ "b/\345\234\206\345\234\206\347\232\204py/list.py" @@ -0,0 +1,111 @@ +# topic: 初学python之列表list +# author:Liu Xiaoxia +# time:2020/4/22 22:40 + +# 创建空列表 +empty = [] +print(empty) + +# 创建字符串列表 +str_0 = ['abc', 'bcd', 'cde'] +print(str_0) + +# str_0.append() +# 创建数字列表 +number = [1, 2, 3] +print(number) + +# 创建混合列表 +mix = ['abc', 2, 'def', 4] +print(mix) + +# 在列表最后添加有且仅有一个元素 +str_0.append('英语好难') +print(str_0) +len(str_0) + +# 用有且仅有一个列表扩展另一个列表,即同时在列表末尾添加多个元素 +str_0.extend(['好好学习', '天天向上']) +print(str_0) + +# 在列表固定位置(下标从0开始)插入元素 +str_0.insert(0, 'aaaaa') +print(str_0) + +# 从列表删除元素(方法) +str_0.remove('英语好难') +print(str_0) + +# 从列表删除元素(函数) +del str_0[0] +print(str_0) + +# 返回列表中要删除的元素值 +# 删除最后一个元素 +str_0.pop() +print(str_0) +# 删除指定元素 +str_0.pop(1) +print(str_0) + + +# 列表切片(分片),一次性获取多个元素, 原列表不变 +# 元素1到元素3(不包含元素3) +print(str_0[1:3]) +# 从列表头到元素3(不包含元素3) +print(str_0[:3]) +# 从元素3到列表末尾 +print(str_0[3:]) +# 输出整个列表 +# 与str_1 = str_0不同 +# str_1 = str_0时,str_0和str_1指向同一块空间;而str_0[:]仅仅是将值给了str_1一份,指向两块不同的空间 +str_1 = str_0[:] +print(str_1) + +# 拼接两个列表 +str_0 = str_0 + number +print(str_0) + +# 复制列表元素 +# 复制后直接输出,原列表不变 +print(number) +print(number * 3) +# 复制后赋值给原列表 +number *= 2 +print(number) + +# 判断元素是否在列表中 +print('好好学习' in str_0) # true +print('哈哈哈' not in str_0) # false + +# dosomething +# 判断元素是否在列表中 +# str_0.extend([['哈哈哈', 'wuwuwu']]) +# print(str_0) +# print('哈哈哈' in str_0) +# print('哈哈哈' in str_0[len(str_0) - 1]) + +# 列表中的列表中的元素 +# print(str_0[6][1]) + +# 列表中数据出现的次数 +print(number.count(2)) + +# 返回参数在列表中第一次出现的位置 +print(str_0.index('cde')) +# 指定查找范围 +print(str_0.index('cde', 0, 5)) + +# 将整个列表翻转(无参数) +str_0.reverse() +print(str_0) + +# sort排序 +# 从小到大排序 +number.sort() +print(number) +number.sort(reverse=False) +print(number) +# 从大到小排序 +number.sort(reverse=True) +print(number) \ No newline at end of file diff --git "a/\345\234\206\345\234\206\347\232\204py/max_score.py" "b/\345\234\206\345\234\206\347\232\204py/max_score.py" new file mode 100644 index 0000000..4a0f63f --- /dev/null +++ "b/\345\234\206\345\234\206\347\232\204py/max_score.py" @@ -0,0 +1,30 @@ +''' +@Description: +@LastEditors: liukai +@Date: 2020-05-15 21:02:38 +@LastEditTime: 2020-05-15 21:10:20 +@FilePath: /pyFile/圆圆的py/max_score.py +''' + +name_dict = {} +while True: + info_list = [] + name = input("姓名:") + if name == "": + break + else: + num = int(input("学号:")) + info_list.append(num) + score = float(input("成绩:")) + info_list.append(score) + name_dict[name] = info_list +for key in name_dict: + print("姓名:%s 学号: %s 成绩: %.1f" % (key, name_dict[key][0], name_dict[key][1])) + +max_score = 0 +for ite in name_dict: + if(name_dict[ite][1] > max_score): + max_score = name_dict[ite][1] + max_index = ite + +print("姓名:%s 学号: %s 成绩: %.1f" % (max_index, name_dict[max_index][0], name_dict[max_index][1])) diff --git "a/\345\234\206\345\234\206\347\232\204py/model.py" "b/\345\234\206\345\234\206\347\232\204py/model.py" new file mode 100644 index 0000000..82fd463 --- /dev/null +++ "b/\345\234\206\345\234\206\347\232\204py/model.py" @@ -0,0 +1,19 @@ +''' +@Description: +@LastEditors: liukai +@Date: 2020-04-24 19:40:51 +@LastEditTime: 2020-05-08 20:19:57 +@FilePath: /pyFile/test.py +''' +# x = map (lambda x: x * x if x % 2 == 0 else 0 , range(10)) +# print([y for y in x]) + +if __name__ == "__main__": + list = [] + for i in range(10): + list.append(int(input())) + list.sort(reverse=True) + print(list[0:1]) + +def test(): + print("Hello python") \ No newline at end of file diff --git "a/Emp/\345\205\254\347\272\246\346\225\260\345\205\254\345\200\215\346\225\260.py" "b/\345\234\206\345\234\206\347\232\204py/\345\205\254\347\272\246\346\225\260\345\205\254\345\200\215\346\225\260.py" similarity index 100% rename from "Emp/\345\205\254\347\272\246\346\225\260\345\205\254\345\200\215\346\225\260.py" rename to "\345\234\206\345\234\206\347\232\204py/\345\205\254\347\272\246\346\225\260\345\205\254\345\200\215\346\225\260.py" diff --git "a/\345\234\206\345\234\206\347\232\204py/\345\210\206\346\224\257\347\232\204\345\265\214\345\245\227\347\273\223\346\236\204.py" "b/\345\234\206\345\234\206\347\232\204py/\345\210\206\346\224\257\347\232\204\345\265\214\345\245\227\347\273\223\346\236\204.py" new file mode 100644 index 0000000..24a691e --- /dev/null +++ "b/\345\234\206\345\234\206\347\232\204py/\345\210\206\346\224\257\347\232\204\345\265\214\345\245\227\347\273\223\346\236\204.py" @@ -0,0 +1,43 @@ +''' +@Description: 分支的嵌套结构 +@LastEditors: liukai +@Date: 2020-04-19 19:44:34 +@LastEditTime: 2020-05-08 21:40:42 +@FilePath: /pyFile/if-else/分支的嵌套结构.py +''' + +#!/usr/bin/python3 +a = int(input('a = ')) +b = int(input('b = ')) +c = int(input('c = ')) + + +def printf(a, b): + "print" + print('maxValue is:', a, ' minValue is:', b) + print(printf.__doc__) #输出函数注释 + return 0 + +# 分支嵌套结构 +if a > b: + if b > c: + print('a > b > c') + printf(a, c) + else: + if a > c: + print('a > c > b') + printf(a, b) + else: + print('c > a > b') + printf(c, b) +else: + if b < c: + print('c > b > a') + printf(c, a) + else: + if c > a: + print('b > c > a') + printf(b, a) + else: + print('b > a > c') + printf(b, c) diff --git "a/\345\234\206\345\234\206\347\232\204py/\345\244\232\345\210\206\346\224\257\347\273\223\346\236\204.py" "b/\345\234\206\345\234\206\347\232\204py/\345\244\232\345\210\206\346\224\257\347\273\223\346\236\204.py" new file mode 100644 index 0000000..1701e50 --- /dev/null +++ "b/\345\234\206\345\234\206\347\232\204py/\345\244\232\345\210\206\346\224\257\347\273\223\346\236\204.py" @@ -0,0 +1,38 @@ +''' +@Description: 判断三个数的最大值和最小值 +@LastEditors: liukai +@Date: 2020-04-19 19:44:07 +@LastEditTime: 2020-05-15 21:02:55 +@FilePath: /pyFile/圆圆的py/多分支结构.py +''' +#!/usr/bin/python3 +a = int(input('a = ')) +b = int(input('b = ')) +c = int(input('c = ')) + +def printf(a, b): + "print" + print('maxValue is:', a,' minValue is:', b); + return 0 + +# 多分支结构即使用if-elif,类似C/C++分割中的switch-case语句 +if a > b: + if b > c: + print('a > b > c') + printf(a, c) + elif a > c: + print('a > c > b') + printf(a, b) + else: + print('c > a > b') + printf(c, b) +elif a < b: + if b < c: + print('c > b > a') + printf(c, a) + elif c > a: + print('b > c > a') + printf(b, a) + else: + print('b > a > c') + printf(b, c) diff --git "a/\345\234\206\345\234\206\347\232\204py/\345\255\227\347\254\246\344\270\262.py" "b/\345\234\206\345\234\206\347\232\204py/\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..63742ed --- /dev/null +++ "b/\345\234\206\345\234\206\347\232\204py/\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,121 @@ +''' +@Description: 字符串 +@LastEditors: liukai +@Date: 2020-04-19 19:46:09 +@LastEditTime: 2020-04-21 08:24:51 +@FilePath: /pyFile/字符串.py +''' + +#!/usr/bin/python3 # 默认使用python3解释器 +#-*- coding: utf-8 -*- # 使用utf-8编码 +import time # 时间库 time.sleep(time); + +print('hello', 'python', sep=',', end='!\n') # sep是自动在元素之间补充的分隔字符 + +print("Loading", end = ""), + +for i in range(20): + print(".",end = '', flush = True) # end将替换末尾的'\n'为'', flush = True将print及时写入到终端 + time.sleep(0.05) + +# 字符串切片 +str = '123456' +print (str) # 输出字符串 +print (str[0:-1]) # 输出第一个到倒数第二个的所有字符 +print (str[0]) # 输出字符串第一个字符 +print (str[2:5]) # 输出从第三个开始到第五个的字符 +print (str[2:]) # 输出从第三个开始的后的所有字符 +print (str * 2) # 输出字符串两次,也可以写成 print (2 * str) +print (str + "TEST") # 连接字符串 +print() + +str1 = 'hello, world!' +# 通过内置函数len计算字符串的长度 +print(len(str1)) # 13 +# 获得字符串首字母大写的拷贝 +print(str1.capitalize()) # Hello, world! +# 获得字符串每个单词首字母大写的拷贝 +print(str1.title()) # Hello, World! +# 获得字符串变大写后的拷贝 +print(str1.upper()) # HELLO, WORLD! +# 从字符串中查找子串所在位置 +print(str1.find('or')) # 8 +print(str1.find('shit')) # -1 +# 与find类似但找不到子串时会引发异常 +# print(str1.index('or')) +# print(str1.index('shit')) +# 检查字符串是否以指定的字符串开头 +print(str1.startswith('He')) # False +print(str1.startswith('hel')) # True +# 检查字符串是否以指定的字符串结尾 +print(str1.endswith('!')) # True +# 将字符串以指定的宽度居中并在两侧填充指定的字符 +print(str1.center(50, '*')) +# 将字符串以指定的宽度靠右放置左侧填充指定的字符 +print(str1.rjust(50, ' ')) +str2 = 'abc123456' +# 检查字符串是否由数字构成 +print(str2.isdigit()) # False +# 检查字符串是否以字母构成 +print(str2.isalpha()) # False +# 检查字符串是否以数字和字母构成 +print(str2.isalnum()) # True +str3 = ' jackfrued@126.com ' +print(str3) +# 获得字符串修剪左右两侧空格之后的拷贝 +print(str3.strip()) + +# 列表list +list1 = [1, 3, 5, 7, 100] +# 添加元素 +list1.append(200) +list1.insert(1, 400) +# 合并两个列表 +# list1.extend([1000, 2000]) +list1 += [1000, 2000] +print(list1) # [1, 400, 3, 5, 7, 100, 200, 1000, 2000] +print(len(list1)) # 9 +# 先通过成员运算判断元素是否在列表中,如果存在就删除该元素 +if 3 in list1: + list1.remove(3) +if 1234 in list1: + list1.remove(1234) +print(list1) # [1, 400, 5, 7, 100, 200, 1000, 2000] +# 从指定的位置删除元素 +list1.pop(0) +list1.pop(len(list1) - 1) +print(list1) # [400, 5, 7, 100, 200, 1000] +# 清空列表元素 +list1.clear() +print(list1) # [] + +# 列表的排序操作 +list1 = ['orange', 'apple', 'zoo', 'internationalization', 'blueberry'] +list2 = sorted(list1) +# sorted函数返回列表排序后的拷贝不会修改传入的列表 +# 函数的设计就应该像sorted函数一样尽可能不产生副作用 +list3 = sorted(list1, reverse=True) +# 通过key关键字参数指定根据字符串长度进行排序而不是默认的字母表顺序 +list4 = sorted(list1, key=len) +print(list1) +print(list2) +print(list3) +print(list4) +# 给列表对象发出排序消息直接在列表对象上进行排序 +list1.sort(reverse=True) +print(list1) + +# 嵌套列表的操作 +lst = [['k', ['qqq', 20, {'k1': ['aa', 3, '1']}, 33], 'xx']] # 例子 +lst[0][1][2]['k1'][0] = lst[0][1][2]['k1'][0].upper() # 将 aa 变成大写AA +lst[0][1][2]['k1'][1] = str(lst[0][1][2]['k1'][1]) # 将列表中的3变成字符串‘3’ +print("修改后的列表:", lst) + +# 字典的相关操作 +dic = {'k1': 'v1', 'k2': ['sb', 'aa'], (1, 2, 3, 4, 5): {'k3': ['2', 100, 'wer']}} +dic['k2'].append(33) # k2对应的值中添加33 +dic['k2'].insert(0, 's') # k2对应的值的第一个位置插入一个元素‘s’ +dic[(1, 2, 3, 4, 5)]['k4'] = 'v4' # 将(1,2,3,4,5)对应的值添加一个键值对 ‘k4’:’v4’ +dic[(1, 2, 3, 4, 5)][(1, 2, 3)] = 'ok' # 将(1,2,3,4,5)对应的值添加一个键值对(1,2,3):‘ok’ +dic[(1, 2, 3, 4, 5)]['k3'][2] = 'qq' # 将’k3’对应的值的‘wer’改为’qq’。 +print("修改后的字典为:", dic) \ No newline at end of file diff --git "a/\345\234\206\345\234\206\347\232\204py/\346\250\241\345\235\227\345\222\214\345\207\275\346\225\260.py" "b/\345\234\206\345\234\206\347\232\204py/\346\250\241\345\235\227\345\222\214\345\207\275\346\225\260.py" new file mode 100644 index 0000000..79a446f --- /dev/null +++ "b/\345\234\206\345\234\206\347\232\204py/\346\250\241\345\235\227\345\222\214\345\207\275\346\225\260.py" @@ -0,0 +1,31 @@ +''' +@Description: 模块和函数 +@LastEditors: liukai +@Date: 2020-04-19 19:45:44 +@LastEditTime: 2020-04-22 18:01:57 +@FilePath: /pyFile/模块和函数.py +''' + +from model import test # 模块导入,如果模块中有主函数,会自动执行模块 +import random # 随机数 +sum = 0 +answer = random.randint(1, 100) + +# 默认参数输出九九乘法表 +def fac(a = 1, b = 10): + for i in range(a, b): + for j in range(1, i + 1): + # print('%d*%d=%d' % (i, j, i * j), end='\t') # 方法一 + # print('{0} * {1} = {2}'.format(a, b, a * b)) # 方法二 + """ + Python 3.6以后,格式化字符串还有更为简洁的书写方式, + 就是在字符串前加上字母f,我们可以使用下面的语法糖来简化上面的代码 + """ + print(f'{i} * {j} = {i * j}', end='\t') + print() + +# 从模块'完数'中导入call函数 +if __name__ == "__main__": + fac(1, 8) # 带有默认参数的函数 + fac(1, 10) + test()