Python pycharm learning 循环语句的使用,列表数据录入(1)

Python pycharm learning 循环语句的使用,列表数据录入
文章编号:Python学【2020】001号
日期:2020-02-10

NO.1

for x in range(4):
    for y in range(3):
        print(f"({x},{y})")

print out
(0,0)
(0,1)
(0,2)
(1,0)
(1,1)
(1,2)
(2,0)
(2,1)
(2,2)
(3,0)
(3,1)
(3,2)*

No.2

numbers = [5,2,5,2,2]
for x_count in numbers:
    print('*'* x_count)

No.3

numbers = [5,2,5,2,2]
for x_count in numbers:
    output = ''
    for count in range(x_count):
        output += 'x'
    print(output)

print out
xxxxx
xx
xxxxx
xx
xx

No.4

names = ['Jhon','Bob','Mosh','Sarah','Mary']
print(names[0])

print out
Jhon

No.5


```python
names = ['Jhon','Bob','Mosh','Sarah','Mary']
#注释:start index from 2 to the end
print(names[2:])   

print out
[‘Mosh’, ‘Sarah’, ‘Mary’]

names = ['Jhon','Bob','Mosh','Sarah','Mary']
# redefine arrays data that index is 0
names[0] = 'Jho'
print(names)

print out
[‘Jho’, ‘Bob’, ‘Mosh’, ‘Sarah’, ‘Mary’]

No.6 Write a program to find the largest number in a list Solution

numbers = [3,6,2,9,4,10]
max =numbers[0]
for number in numbers:
    if number > max:
        max = number
print(max)

print out
10

No.7

#2D list(two dimentional list)(square bracket)

note:
matrix = [
[1,2,3]…1st row
[4,5,6)…2nd row
]
matrix[0][1],0row,1column

No.1

matrix = [
[1,2,3],
[4,5,6],
[7,8,9]
    ]
print(matrix[0][1])

#print out
2

No.2

matrix = [
[1,2,3],
[4,5,6],
[7,8,9]
    ]
#append data
matrix[0][1]=20
print(matrix)

#print out
[1,20,3],
[4,5,6],
[7,8,9]

No.3

matrix = [
[1,2,3],
[4,5,6],
[7,8,9]
    ]
for row in matrix:
    for item in row:
        print(item)

#print out
1
2
3
4
5
6
7
8
9

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值