如何用PYTHON里LIST和FOR LOOPS

 时间:2024-10-14 22:25:41

1、打开JUPYTER NOTEBOOK,新建一个空白的PY文档。

如何用PYTHON里LIST和FOR LOOPS

2、fruit = ["apple", "peach", "orange", "banana"]for special_fruit in fruit: print(special_fruit)新建一个列表,用FOR LOOPS简单地打印出来。

如何用PYTHON里LIST和FOR LOOPS

3、fruit = ["apple", "peach", "orange", "banana", "pear"]for special_fruit in fruit: if special_fruit == "orange": print("Eat it.") break print(special_fruit)如果我们只为了找到其中某一数据,那么可以用BREAK来停止继续的操作。

如何用PYTHON里LIST和FOR LOOPS

4、fruit = ["apple", "peach", "orange", "banana", "pear"]for special_fruit in fruit: if special_fruit == "orange": print("Eat it.") continue print(special_fruit)但是有时候找到数据我们需要继续运行,那么就可以用CONTINUE。

如何用PYTHON里LIST和FOR LOOPS

5、fruit = ["apple", "peach", "orange", "banana", "pear"]for special_fruit in fruit: for index in "12345": print(index, special_fruit)如果要在列表关键词前加数字也是可以的。

如何用PYTHON里LIST和FOR LOOPS

6、fruit = ["apple", "peach", "orange", "banana", "pear"]do_it = ["eat the ", "cook the ", "slice the ", "water the ", "take the "]for special_fruit in fruit: for dododo in do_it: print(dododo, special_fruit)同时用上两组列表,这样就可以打印出来合并的句子。

如何用PYTHON里LIST和FOR LOOPS
  • 如何运用PYTHON的嵌套FOR LOOPS循环
  • 如何复制PYTHON里的列表list
  • 如何用PYTHON里LIST中sort()方法
  • python里lambda的使用
  • python里面re.sub()函数的使用方法
  • 热门搜索
    单位隶属怎么填 偷东西怎么判刑 磁力链接怎么用 眼睛怎么变大 新鲜天麻怎么吃 海信电视怎么投屏 怎么去黑眼圈 怎么理财 电脑蓝屏怎么办 番茄炒蛋怎么做