# Enter a code
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for n in L:
if n not in S:
S.add(n)
else:
S.remove(n)
print(S)
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for n in L:
if n not in S:
S.add(n)
else:
S.remove(n)
print(S)
2023-12-27
# Enter a code
L = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
L.append('Zero')
L.append('Phoebe')
L.append('Gen')
L.sort()
print(L)
L = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
L.append('Zero')
L.append('Phoebe')
L.append('Gen')
L.sort()
print(L)
2023-12-27
T = ('Alice', 'Bob', 'Candy', 'David', 'Ellena')
# 通过下标的方式访问元素
print(T[0]) # ==> Alice
print(T[4]) # ==> Ellena
# 切片
print(T[1:3]) # ==> ('Bob', 'Candy')
candy错了吧,应该是David吧
# 通过下标的方式访问元素
print(T[0]) # ==> Alice
print(T[4]) # ==> Ellena
# 切片
print(T[1:3]) # ==> ('Bob', 'Candy')
candy错了吧,应该是David吧
2023-12-25
num = 3.14 * 1.57
print (round (num , 2))
round 需要嵌套在print里面
print (round (num , 2))
round 需要嵌套在print里面
2023-12-19
直接使用 get 方法如果找不到默认返回 None 的特性,代码如下。
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
names = ["Alice", "Bob", "Candy", "Mimi", "David"]
for name in names :
print(d.get(name))
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
names = ["Alice", "Bob", "Candy", "Mimi", "David"]
for name in names :
print(d.get(name))
2023-12-13
print(r'''"To be, or not to be": that is the question.
Whether it's nobler in the mind to suffer.''')
Whether it's nobler in the mind to suffer.''')
2023-12-07