s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
print('-----------')
c_set = set()
if not s2.isdisjoint(s1):
for item in s1:
if item in s2:
c_set.add(item)
print(c_set)
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
print('-----------')
c_set = set()
if not s2.isdisjoint(s1):
for item in s1:
if item in s2:
c_set.add(item)
print(c_set)
2025-07-30
不知道对不对
a = 3.1415926;
b = 'Learn Python in imooc.';
c = 100;
d = 0b1101;
print(type(a),type(b),type(c),type(d))
a = 3.1415926;
b = 'Learn Python in imooc.';
c = 100;
d = 0b1101;
print(type(a),type(b),type(c),type(d))
2025-07-25
# Enter a code
d = {
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
L= ([50, 61, 66],[80, 61, 66],[88, 75, 90])
num = 0
for item in d:
d[item] = L[num]
i = num+1
print(d)
d = {
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
L= ([50, 61, 66],[80, 61, 66],[88, 75, 90])
num = 0
for item in d:
d[item] = L[num]
i = num+1
print(d)
2025-07-24
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
L = ('Alice', 'Bob', 'Candy', 'Mimi', 'David')
for item in L:
print('{}:{}'.format(item,d.get(item)))
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
L = ('Alice', 'Bob', 'Candy', 'Mimi', 'David')
for item in L:
print('{}:{}'.format(item,d.get(item)))
2025-07-24
L = [[1, 2, 3], [5, 3, 2], [7, 3, 2]]
for item in L:
num = 1
for i in item:
num = i*num
print(num)
for item in L:
num = 1
for i in item:
num = i*num
print(num)
2025-07-22
L = ['Alice', 66, 'Bob', True, 'False', 100]
num = 1
for c in L:
if num % 2 == 0:
print(c)
num += 1
num = 1
for c in L:
if num % 2 == 0:
print(c)
num += 1
2025-07-22
age = 19
if age >= 18:
temp = 'adult {}'
print(temp.format(age))
if age >= 18:
temp = 'adult {}'
print(temp.format(age))
2025-07-21
# Enter a code
template = 'Life is {0}, {1} {2} {3}'
template1 = 'Life is {a},{b},{c} {d}'
print(template.format("short","you","need","python"))
aa='short'
bb = 'you'
cc = 'need'
dd = 'python'
print(template1.format(a=aa,b=bb,c=cc,d=dd))
template = 'Life is {0}, {1} {2} {3}'
template1 = 'Life is {a},{b},{c} {d}'
print(template.format("short","you","need","python"))
aa='short'
bb = 'you'
cc = 'need'
dd = 'python'
print(template1.format(a=aa,b=bb,c=cc,d=dd))
2025-07-21
print(r'''To be, or not to be: that is the question.Whether it's nobler in the mind to suffer.''')
2025-07-21
Python遍历dict
通过直接print(d),我们打印出来的是完整的一个dict;有时候,我们需要把dict中m(满足)一定条件的元素打印出来
通过直接print(d),我们打印出来的是完整的一个dict;有时候,我们需要把dict中m(满足)一定条件的元素打印出来
2025-07-18
def sub_sum(n):
if n <= 0:
return 0
return n+sub_sum(n-1)
n=100
print(sub_sum(n))
if n <= 0:
return 0
return n+sub_sum(n-1)
n=100
print(sub_sum(n))
2025-07-06
最新回答 / 不吃香菜吖
d = { 'Alice': 45, 'Bob': 60, 'Candy': 75, 'David': 86, 'Ellena': 49}# name = input('to del whose score:')name = 'Alice'try: d.pop(name) print(name + ' deleted')except: print(name + ' none')
2025-05-29