From 66027e26b48b34154af3d76d13f293351f6c9a28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E8=8B=B1=E6=9D=B0?= <327782001@qq.com> Date: Fri, 2 Jun 2023 10:30:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=88=87=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\270\347\224\250\346\223\215\344\275\234.py" | 8 ++++++++ ...1\250\347\232\204\345\276\252\347\216\257.py" | 12 ++++++++++-- .../06_\345\255\227\347\254\246\344\270\262.py" | 5 +++++ ...0\227\345\222\214\345\210\207\347\211\207.py" | 16 +++------------- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git "a/05_\346\225\260\346\215\256\345\256\271\345\231\250/02_list\345\210\227\350\241\250\347\232\204\345\270\270\347\224\250\346\223\215\344\275\234.py" "b/05_\346\225\260\346\215\256\345\256\271\345\231\250/02_list\345\210\227\350\241\250\347\232\204\345\270\270\347\224\250\346\223\215\344\275\234.py" index c8595b1..0a0a6ac 100644 --- "a/05_\346\225\260\346\215\256\345\256\271\345\231\250/02_list\345\210\227\350\241\250\347\232\204\345\270\270\347\224\250\346\223\215\344\275\234.py" +++ "b/05_\346\225\260\346\215\256\345\256\271\345\231\250/02_list\345\210\227\350\241\250\347\232\204\345\270\270\347\224\250\346\223\215\344\275\234.py" @@ -51,7 +51,15 @@ count = len(mylist) print(f"列表的元素数量总共有:{count}个") +# 7. 删除某元素在列表中的第一个匹配项 +mylist = ["itcast", "itheima", "itcast", "itheima", "python"] +mylist.reverse() +print(f"通过reverse方法翻转后,列表的结果是:{mylist}") +# 7. 删除某元素在列表中的第一个匹配项 +mylist = ["itcast", "itheima", "itcast", "itheima", "python"] +mylist.remove("itheima") +print(f"通过remove方法移除元素后,列表的结果是:{mylist}") diff --git "a/05_\346\225\260\346\215\256\345\256\271\345\231\250/04_list\345\210\227\350\241\250\347\232\204\345\276\252\347\216\257.py" "b/05_\346\225\260\346\215\256\345\256\271\345\231\250/04_list\345\210\227\350\241\250\347\232\204\345\276\252\347\216\257.py" index bd58671..485aa2f 100644 --- "a/05_\346\225\260\346\215\256\345\256\271\345\231\250/04_list\345\210\227\350\241\250\347\232\204\345\276\252\347\216\257.py" +++ "b/05_\346\225\260\346\215\256\345\256\271\345\231\250/04_list\345\210\227\350\241\250\347\232\204\345\276\252\347\216\257.py" @@ -11,13 +11,21 @@ def list_while_func(): mylist = ["传智教育", "黑马程序员", "Python"] # 循环控制变量:通过下标索引来控制,默认0 # 每一次循环将下标苏姚 + index = 0 + while index < len(mylist): + print(mylist[index]) + index += 1 - - +# list_while_func() def list_for_func(): """ 使用for循环遍历列表的演示函数 :return: """ + mylist = ["传智教育", "黑马程序员", "Python"] + for e in mylist: + print(e) + +list_for_func() diff --git "a/05_\346\225\260\346\215\256\345\256\271\345\231\250/06_\345\255\227\347\254\246\344\270\262.py" "b/05_\346\225\260\346\215\256\345\256\271\345\231\250/06_\345\255\227\347\254\246\344\270\262.py" index aa8e429..18aa00a 100644 --- "a/05_\346\225\260\346\215\256\345\256\271\345\231\250/06_\345\255\227\347\254\246\344\270\262.py" +++ "b/05_\346\225\260\346\215\256\345\256\271\345\231\250/06_\345\255\227\347\254\246\344\270\262.py" @@ -38,3 +38,8 @@ print(f"字符串{my_str}中it出现的次数是:{count}") # 统计字符串的长度, len() num = len(my_str) print(f"字符串{my_str}的长度是:{num}") + + +my_str = "12itheima and itcast21" +new_my_str = my_str.strip("231") +print(f"字符串{my_str}被strip('12')后,结果:{new_my_str}") \ No newline at end of file diff --git "a/05_\346\225\260\346\215\256\345\256\271\345\231\250/08_\345\272\217\345\210\227\345\222\214\345\210\207\347\211\207.py" "b/05_\346\225\260\346\215\256\345\256\271\345\231\250/08_\345\272\217\345\210\227\345\222\214\345\210\207\347\211\207.py" index fb047f2..c7197b0 100644 --- "a/05_\346\225\260\346\215\256\345\256\271\345\231\250/08_\345\272\217\345\210\227\345\222\214\345\210\207\347\211\207.py" +++ "b/05_\346\225\260\346\215\256\345\256\271\345\231\250/08_\345\272\217\345\210\227\345\222\214\345\210\207\347\211\207.py" @@ -1,37 +1,27 @@ """ 演示对序列进行切片操作 """ - # 对list进行切片,从1开始,4结束,步长1 my_list = [0, 1, 2, 3, 4, 5, 6] -result1 = my_list[1:4] # 步长默认是1,所以可以省略不写 +result1 = my_list[1:4] # 步长默认是1,所以可以省略不写 print(f"结果1:{result1}") - # 对tuple进行切片,从头开始,到最后结束,步长1 my_tuple = (0, 1, 2, 3, 4, 5, 6) -result2 = my_tuple[:] # 起始和结束不写表示从头到尾,步长为1可以省略 +result2 = my_tuple[:] # 起始和结束不写表示从头到尾,步长为1可以省略 print(f"结果2:{result2}") - # 对str进行切片,从头开始,到最后结束,步长2 my_str = "01234567" result3 = my_str[::2] print(f"结果3:{result3}") - - # 对str进行切片,从头开始,到最后结束,步长-1 my_str = "01234567" -result4 = my_str[::-1] # 等同于将序列反转了 +result4 = my_str[::-1] # 等同于将序列反转了 print(f"结果4:{result4}") - - # 对列表进行切片,从3开始,到1结束,步长-1 my_list = [0, 1, 2, 3, 4, 5, 6] result5 = my_list[3:1:-1] print(f"结果5:{result5}") - - # 对元组进行切片,从头开始,到尾结束,步长-2 my_tuple = (0, 1, 2, 3, 4, 5, 6) result6 = my_tuple[::-2] print(f"结果6:{result6}") - -- GitLab