T = ('Alice', 'Bob', 'Candy', 'David', 'Ellena')
# 通過下標的方式訪問元素
print(T[0]) # ==> Alice
print(T[4]) # ==> Ellena
# 切片
print(T[1:3]) # ==> ('Bob', 'Candy')
# 通過下標的方式訪問元素
print(T[0]) # ==> Alice
print(T[4]) # ==> Ellena
# 切片
print(T[1:3]) # ==> ('Bob', 'Candy')
2023-02-03
在計算a and b時,如果 a 是 False,則根據與運算法則,整個結果必定為 False,因此返回 a;如果 a 是 True,則整個計算結果必定取決與 b,因此返回 b。
在計算a or b時,如果 a 是 True,則根據或運算法則,整個計算結果必定為 True,因此返回 a;如果 a 是 False,則整個計算結果必定取決于 b,因此返回 b。
在計算a or b時,如果 a 是 True,則根據或運算法則,整個計算結果必定為 True,因此返回 a;如果 a 是 False,則整個計算結果必定取決于 b,因此返回 b。
2023-02-02
def func(**kwargs):
s = 0
for i in n:
print('name:{},gander:{},age:{}'.format(n[s],g[s],a[s]))
s += 1
n = ['Alice','Bob','Candy']
g = ['F','M','F']
a = ['18','19','20']
func(names = n,gander = g,age = a)
s = 0
for i in n:
print('name:{},gander:{},age:{}'.format(n[s],g[s],a[s]))
s += 1
n = ['Alice','Bob','Candy']
g = ['F','M','F']
a = ['18','19','20']
func(names = n,gander = g,age = a)
2023-01-10
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
if (s1.isdisjoint(s2) == False):
for i in s2:
if i in s1:
print(i)
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
if (s1.isdisjoint(s2) == False):
for i in s2:
if i in s1:
print(i)
2023-01-04
# coding=utf-8
def sub_sum(L):
odd = 0
even = 0
for x in L:
if x%2 == 0:
even += x
else:
odd += x
return odd,even
print(sub_sum([1,2,3,4,5,6]))
def sub_sum(L):
odd = 0
even = 0
for x in L:
if x%2 == 0:
even += x
else:
odd += x
return odd,even
print(sub_sum([1,2,3,4,5,6]))
2023-01-04
# Enter a code
def square_of_sum(L):
sum = 0
for x in L:
sum += x * x
return sum
list1 = list()
num = 1
while num <= 100:
list1.append(num)
num += 1
print(list1)
print(square_of_sum(list1))
def square_of_sum(L):
sum = 0
for x in L:
sum += x * x
return sum
list1 = list()
num = 1
while num <= 100:
list1.append(num)
num += 1
print(list1)
print(square_of_sum(list1))
2023-01-04
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
s3 = set()
if not s1.isdisjoint(s2):
for x in s1:
if x in s2:
s3.add(x)
print(s3)
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
s3 = set()
if not s1.isdisjoint(s2):
for x in s1:
if x in s2:
s3.add(x)
print(s3)
2023-01-03
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for x in L:
if x in S:
S.remove(x)
else:
S.add(x)
print(S)
S = set([1, 3, 5, 7, 9, 11])
for x in L:
if x in S:
S.remove(x)
else:
S.add(x)
print(S)
2023-01-03