T = (1, 'CH', [3, 4])
T = list(T)
T[2]=tuple(T[2])
print(tuple(T))
T = list(T)
T[2]=tuple(T[2])
print(tuple(T))
2021-03-23
a='python'
print('hello',a and 'world') #==>hello, python
在and语句下,a值为true,所以运算结果取决于前者
b=''
print('hello',b or 'world') #==>hello, world
在or语句下,b值为false(空,0,None),所以运算结果取后者
print('hello',a and 'world') #==>hello, python
在and语句下,a值为true,所以运算结果取决于前者
b=''
print('hello',b or 'world') #==>hello, world
在or语句下,b值为false(空,0,None),所以运算结果取后者
2021-03-20
搞那么复杂
def sub_sum(l):
j_sum=0
o_sum=0
for n in l:
if n%2 == 0 :
o_sum += n
else:
j_sum += n
return j_sum,o_sum
l=[1,3,5,2,4,6,7,8,9,10]
s=sub_sum(l)
print('奇数和={}'.format(s[0]))
print('偶数和={}'.format(s[1]))
def sub_sum(l):
j_sum=0
o_sum=0
for n in l:
if n%2 == 0 :
o_sum += n
else:
j_sum += n
return j_sum,o_sum
l=[1,3,5,2,4,6,7,8,9,10]
s=sub_sum(l)
print('奇数和={}'.format(s[0]))
print('偶数和={}'.format(s[1]))
2021-03-19
# Enter a code
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for v1 in L:
if v1 in S:
S.remove(v1)
else:
S.add(v1)
print(S)
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for v1 in L:
if v1 in S:
S.remove(v1)
else:
S.add(v1)
print(S)
2021-03-19
names1= []
names2=['Jenny', 'Ellena', 'Alice', 'Candy', 'David', 'Hally', 'Bob', 'Isen', 'Karl']
names1_set=set(names1)
#方法一
for v in names2:
names1_set.add(v)
print(names1_set)
#方法二
names1_set.update(names2)
print(names1_set)
names2=['Jenny', 'Ellena', 'Alice', 'Candy', 'David', 'Hally', 'Bob', 'Isen', 'Karl']
names1_set=set(names1)
#方法一
for v in names2:
names1_set.add(v)
print(names1_set)
#方法二
names1_set.update(names2)
print(names1_set)
2021-03-19
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
for x in s1:
if s1.isdisjoint(s2) == False:
print(x)
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
for x in s1:
if s1.isdisjoint(s2) == False:
print(x)
2021-03-19
# Enter a code
names = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
names.insert(0,'Ellena')
names.pop(2)
names[-1] = 'Bob'
print(names)
names = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
names.insert(0,'Ellena')
names.pop(2)
names[-1] = 'Bob'
print(names)
2021-03-17
d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
for key in d:
value=d[key]
for score in value:
print(key,score)
for key in d:
value=d[key]
for score in value:
print(key,score)
2021-03-17
# Enter a code
# -*- coding: UTF-8 -*-
# Enter a code
# -*- coding: UTF-8 -*-
#age = int(input('请输入年龄 '))
age = 6
if age >= 18:
print('成年人')
elif 6 <= age <= 18:
print('青少年')
elif 3 <= age <= 6:
print('小孩子')
elif age <= 3:
print('婴儿')
else:
print('出现错误')
# -*- coding: UTF-8 -*-
# Enter a code
# -*- coding: UTF-8 -*-
#age = int(input('请输入年龄 '))
age = 6
if age >= 18:
print('成年人')
elif 6 <= age <= 18:
print('青少年')
elif 3 <= age <= 6:
print('小孩子')
elif age <= 3:
print('婴儿')
else:
print('出现错误')
2021-03-17
d = {
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
l=[50, 61, 66],[80, 61, 66],[88, 75, 90]
print(l[0])
n=0
for v2 in d:
d[v2] = l[n]
print(d,end='\n')
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
l=[50, 61, 66],[80, 61, 66],[88, 75, 90]
print(l[0])
n=0
for v2 in d:
d[v2] = l[n]
print(d,end='\n')
2021-03-17
num=0
sum=0
while num<=1000:
if num%2==0:
sum+=num
num+=1
else:
num += 1
continue
print('sum=',sum)
sum=0
while num<=1000:
if num%2==0:
sum+=num
num+=1
else:
num += 1
continue
print('sum=',sum)
2021-03-16