python中for in语句有什么用法

Python中for in是循环结构的一种,经常用于遍历字符串、列表,元组,字典等,格式为for x in y:,执行流程:x依次表示y中的一个元素,遍历完所有元素循环结束。

for in 说明:也是循环结构的一种,经常用于遍历字符串、列表,元组,字典等。

格式:
for x in y:
循环体

执行流程:x依次表示y中的一个元素,遍历完所有元素循环结束。

例1:遍历字符串

s = 'I love you more than i can say'
for i in s:
    print(i)

例2:遍历列表

l = ['鹅鹅鹅', '曲项向天歌', '锄禾日当午', '春种一粒粟']
for i in l:
    print(i)
# 可以获取下表,enumerate每次循环可以得到下表及元素
for i, v in enumerate(l):
    print(i, v)

例3:遍历字典

d = {'a':'apple', 'b':'banana', 'c':'car', 'd': 'desk'}
for key in d:
    # 遍历字典时遍历的是键
    print(key, d.get(key))
# for key, value in d.items():
# 上下两种方式等价 d.items() <=> dict.items(d)
for key, value in dict.items(d):
    print(key, value)

列表生成式

可迭代对象:列表、元组、字典等都是可迭代对象,就是可以遍历的对象

range,用法如下:

print(range(10))
# 可以生成从0开始到10的连续整数的迭代对象
print(range(0, 10))
# 可以遍历
for i in range(10):
    print(i)
# 强制转换为列表
print(list(range(1, 11)))

列表生成式:快速生成具有特定规律的列表
# 列表生成式
print([i for i in range(1, 11)])
print([i*2 for i in range(1, 11)])
print([i*i for i in range(1, 11)])
print([str(i) for i in range(1, 11)])
print([i for i in range(1, 11) if i % 2 == 0])
  • 3
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
编译好的x265,带y4m文件 Syntax: x265 [options] infile [-o] outfile infile can be YUV or Y4M outfile is raw HEVC bitstream Executable Options: -h/--help Show this help text and exit -V/--version Show version info and exit Output Options: -o/--output Bitstream output file name --log-level Logging level: none error warning info debug full. Default info --no-progress Disable CLI progress reports --[no-]cu-stats Enable logging stats about distribution of cu across all modes. Default disabled Input Options: --input Raw YUV or Y4M input file name. `-` for stdin --fps Source frame rate (float or num/denom), auto-detected if Y4M --input-res WxH Source picture size [w x h], auto-detected if Y4M -f/--frames Maximum number of frames to encode. Default all --seek First frame to encode Quality reporting metrics: --[no-]ssim Enable reporting SSIM metric scores. Default disabled --[no-]psnr Enable reporting PSNR metric scores. Default disabled Profile, Level, Tier: --profile Enforce an encode profile: main, main10, mainstillpicture --level-idc Force a minumum required decoder level (as '5.0' or '50') --[no-]high-tier If a decoder level is specified, this modifier selects High tier of that level Threading, performance: --threads Number of threads for thread pool (0: detect CPU core count, default) -F/--frame-threads Number of concurrently encoded frames. 0: auto-determined by core count --[no-]wpp Enable Wavefront Parallel Processing. Default enabled --[no-]pmode Parallel mode analysis. Default disabled --[no-]pme Parallel motion estimation. De

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值