为了账号安全,请及时绑定邮箱和手机立即绑定
课程 \ Python3 入门教程(新版)

Python3 入门教程(新版)

7-3 Python添加dict元素
# Enter a code

d = {
'Alice': [45],
'Bob': [60],
'Candy': [75]
}
aliceScore = [50, 61, 66]
bobScore = [80,61,66]
candyScore = [88, 75, 90]

scores = {
'Alice': aliceScore,
'Bob': bobScore,
'Candy': candyScore
}
print(scores)

for name in d:
if name in scores:
for score in scores[name]:
d[name].append(score)
print(d)
2023-01-17 查看完整代码
7-2 Python读取dict元素
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
print(d.get('Alice'))
print(d.get('Bob'))
print(d.get('Candy'))
print(d.get('Mimi'))
print(d.get('David'))
2023-01-17 查看完整代码
7-1 什么是dict
# Enter a code
d={
'Alice':45,
'Bob':60,
'Cangdy':75,
'David':86,
'Elleena':49,
'Gaven': 86
}
print(d) #code uft-8
2023-01-14 查看完整代码
6-1 什么是tuple
# Enter a code
T = tuple(range(0,10))
print(T)

L = list(T)
print(L)
2023-01-14 查看完整代码
6-4 Python的可变tuple
# Enter a code
T = (1, 'CH', [3, 4])
T = list(T)
T[2] = tuple(list(T[2]))
print(tuple(T))
2023-01-13 查看完整代码
6-3 Python创建单个元素的tuple
# Enter a code
T = ((1+2), ((1+2),), ('a'+'b'), (1, ), (1,2,3,4,5))
count = 0
for t in T:
if isinstance(t,tuple):
count += 1
print(count)
2023-01-13 查看完整代码
6-2 访问tuple元素的其他方法
# Enter a code
T = (100, 69, 29, 100, 72, 99, 98, 100, 75, 100, 100, 42, 88, 100)
print(T.count(100))
2023-01-13 查看完整代码
5-8 Python二维list
# Enter a code
L = [[1, 2, 3], [5, 3, 2], [7, 3, 2]]
for item1 in L:
square = 1
for item2 in item1:
square = square*item2
print(square)
2023-01-12 查看完整代码
7-5 Python删除dict元素
# Enter a code
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
name = 'Alice'
if name in d.keys():
d.pop(name)
else:
print('{} not in d'.format(name))

print(d)
2023-01-12 查看完整代码
7-4 Python更新dict元素
# Enter a code
d={'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
d['Alice']=45,60
print(d)
2023-01-12 查看完整代码
5-7 Python替换list中的元素
# Enter a code
L = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
temp0 = L[0]
temp1 = L[1]
temp2 = L[2]
temp3 = L[3]
temp4 = L[4]

L[0] = temp4
L[1] = temp0
L[2] = temp2
L[3] = temp3
L[4] = temp1

print(L)
2023-01-09 查看完整代码
5-6 Python从list删除元素
# Enter a code
L = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
L.pop(2)
L.pop(2)
print(L)
print('...-...')
2023-01-09 查看完整代码
5-5 Python向list添加新的元素
# Enter a code
L = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
L.append('Zero')
L.insert(5,'Gen')
L.insert(6,'Phoebe')

print(L)
2023-01-09 查看完整代码
5-4 Python倒序访问list
# Enter a code
L = [95.5, 85, 59, 66, 72]
print(L[-5])
print(L[-4])
print(L[-1])
2023-01-09 查看完整代码
5-3 Python按索引访问list
# Enter a code
L = [95.5, 85, 59, 66, 72]
print(L[0])
print(L[1])
print(L[4])
2023-01-09 查看完整代码
5-2 Python按顺序访问list
# Enter a code
List1 = ['Alice', 66, 'Bob', True, 'False', 100]
for item in List1:
if type(item) == 'int' and item % 2 == 0:
print(item)
2023-01-08 查看完整代码
5-1 什么是容器、什么是list
# Enter a code
scoree = ['Alice', 'Chinese', 92, 'Math', 75, 'English', 99]
print(scoree)
2023-01-08 查看完整代码
4-8 Python之嵌套循环
# Enter a code
s1 = 'ABC'
s2 = '123'
s3 = 'xyz'
for x in s1:
for y in s2:
for z in s3:
print(x+y+z)
2023-01-08 查看完整代码
4-7 Python之continue继续循环
# Enter a code
n = 0
s = 0
while n <= 1000:
n += 1
if n % 2 == 1:
continue
s +=+ n
print(s)
2023-01-08 查看完整代码
4-6 Python之break跳出循环
# Enter a code
num = 0
sum = 0
while True:
if num > 1000:
break
if num % 2 == 0:
sum = sum + num
num = num + 1
print(sum)
2023-01-08 查看完整代码
首页上一页123下一页尾页
意见反馈 帮助中心 APP下载
官方微信