首页 > 其他分享 >循环控制语句 之 with_list

循环控制语句 之 with_list

时间:2023-01-20 09:33:05浏览次数:40  
标签:语句 obj debug list item 循环 print

with_list

不展开循环嵌套的列表。功能类似于

for i in zip([1,2,3],['a','b','c']):
    print(i)
- hosts: all
  tasks:
  - name: debug
    debug:
      msg: "{{ item }}"
    with_list
    - ["a","b","c"]
    - [1,2,3]

而with_item 会展开循环,可以理解为

def with_item(obj):
    for i in obj:
        if isinstance(i ,list ):
            with_item(i)
        else:
            print(i)

with_item([[1,2,3],['a','b',['c','d']]])

标签:语句,obj,debug,list,item,循环,print
From: https://www.cnblogs.com/wangend/p/17062426.html

相关文章