num0=[]
num1=[]
flag=False
for itemL in L:
for itemS in S:
if itemL==itemS:
num0.append(itemS)
flag=True
break
if flag==False:
num1.append(itemL)
if flag==True:
flag=False
num1=[]
flag=False
for itemL in L:
for itemS in S:
if itemL==itemS:
num0.append(itemS)
flag=True
break
if flag==False:
num1.append(itemL)
if flag==True:
flag=False
2025-08-17
# -*- coding: utf-8 -*-
調(diào)用函數(shù)出現(xiàn)中文需備注上訴內(nèi)容。
調(diào)用函數(shù)出現(xiàn)中文需備注上訴內(nèi)容。
2025-08-12
def func(**kwargs):
n = kwargs['names']
g = kwargs['gender']
a = kwargs['age']
index = 0
for name,gender,age in zip(n, g, a):
print('name: {},gender: {},age: {}'.format(name,gender,age))
func(name = ['吳宣儀','趙露思','高亞星'], gender = ['girl', 'girl', 'girl'], age = [25,28,27])
n = kwargs['names']
g = kwargs['gender']
a = kwargs['age']
index = 0
for name,gender,age in zip(n, g, a):
print('name: {},gender: {},age: {}'.format(name,gender,age))
func(name = ['吳宣儀','趙露思','高亞星'], gender = ['girl', 'girl', 'girl'], age = [25,28,27])
2025-08-12
def greet(param='world'):
print('Hello,{}.'.format(param))
greet()
greet(123)
print('Hello,{}.'.format(param))
greet()
greet(123)
2025-08-12
def func(p):
sum_c = 0
mul = 1
if isinstance(p,list):
for i in param:
sum_c += i
return sum_c
if isinstance(p,tuple):
for i in range(len(p)):
mul *= p[i]
return mul
c = func((1,2,15))
print(c)
p = func([1,12,3])
print(p)
sum_c = 0
mul = 1
if isinstance(p,list):
for i in param:
sum_c += i
return sum_c
if isinstance(p,tuple):
for i in range(len(p)):
mul *= p[i]
return mul
c = func((1,2,15))
print(c)
p = func([1,12,3])
print(p)
2025-08-12
def sum_num(n):
if n == 1:
return 1
return n + sum_num(n-1)
sum_number = sum_num(100)
print(sum_number)
if n == 1:
return 1
return n + sum_num(n-1)
sum_number = sum_num(100)
print(sum_number)
2025-08-12
def sub_sum(list):
sum_even = 0
sum_odd = 0
for i in range(len(list)):
if i % 2 == 0:
sum_even += list[i]
else:
sum_odd += list[i]
return sum_even,sum_odd
s_even,s_odd = sub_sum([1,2,5,9,3,11])
print("s_even: ",s_even)
print("s_odd: ",s_odd)
sum_even = 0
sum_odd = 0
for i in range(len(list)):
if i % 2 == 0:
sum_even += list[i]
else:
sum_odd += list[i]
return sum_even,sum_odd
s_even,s_odd = sub_sum([1,2,5,9,3,11])
print("s_even: ",s_even)
print("s_odd: ",s_odd)
2025-08-12
def square_of_sum(list):
sum = 0
for i in list:
sum += i * i
return sum
sum_num = square_of_sum([1,2,3])
print(sum_num)
sum = 0
for i in list:
sum += i * i
return sum
sum_num = square_of_sum([1,2,3])
print(sum_num)
2025-08-12
def sum(list):
sum = 0
for i in list:
sum += i * i
return sum
list_num = []
for i in range(1,100):
list_num.append(i)
sum_num = sum(list_num)
print(sum_num)
sum = 0
for i in list:
sum += i * i
return sum
list_num = []
for i in range(1,100):
list_num.append(i)
sum_num = sum(list_num)
print(sum_num)
2025-08-12
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
result = s1.isdisjoint(s2)
print(result)
s = set()
for i in s1:
if i in s2:
s.add(i)
print(s)
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
result = s1.isdisjoint(s2)
print(result)
s = set()
for i in s1:
if i in s2:
s.add(i)
print(s)
2025-08-12
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for i in L:
if i in S:
continue
S.add(i)
print(S)
S = set([1, 3, 5, 7, 9, 11])
for i in L:
if i in S:
continue
S.add(i)
print(S)
2025-08-12
T = (1, 'CH', [3, 4])
L = list(T)
L[2] = tuple(L[2])
T = tuple(L)
print(T)
L = list(T)
L[2] = tuple(L[2])
T = tuple(L)
print(T)
2025-08-11
T = ((1+2), ((1+2),), ('a'+'b'), (1, ), (1,2,3,4,5))
count = 0
for i in T:
if type(i) == tuple:
count += 1
print(count)
count = 0
for i in T:
if type(i) == tuple:
count += 1
print(count)
2025-08-11