如何用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()函数的使用方法
  • 热门搜索
    牙齿黄怎么办 海蛎子怎么吃 枇杷怎么吃 灭火器怎么用 我的世界信标怎么做 别人欠钱不还怎么办 简单学习网怎么样 懵懂怎么读 动物怎么过冬 鼻塞怎么快速通气