运维开发网
广告位招商联系QQ:123077622
 
广告位招商联系QQ:123077622

python 基础学习系列(四)

运维开发网 https://www.qedev.com 2021-03-16 09:11 出处:51CTO 作者:进击的闪电
python

FOR循环

for item in range(5,10,2):

print(item)

prices =[10,20,30]

total = 0

for price in prices:

total += price

print(f'Total:{total}')

numbers = [5,2,5,2,2]

for x_count in numbers:

print('x'* x_count)

numbers = [5,2,5,2,2]

for x_count in numbers:

output=''

for count in range(x_count):

output += 'x'

print(output)

运行结果如下:

xxxxx

xx

xxxxx

xx

xx

找出最大的数

numbers=[3,6,2,8,4,10]

max=numbers[0]

for number in numbers:

if number > max:

max=number

print(max)

列出矩阵中的所有项

matrix=[

[1,2,3],

[4,5,6],

[7,8,9]

]

for row in matrix:

for item in row:

print(item)

二维数组

matrix=[

[1,2,3],

[4,5,6],

[7,8,9]

]

for row in matrix:

for item in row:

print(item)

扫码领视频副本.gif

0

精彩评论

暂无评论...
验证码 换一张
取 消