最新回答 / qq_迷失在天堂里云_0
remove函数只能删除首个满足条件的数,不如换种方式
c=[2,5,2,3,3,4,8,'a','b','c','d',1.1] c2=[] for t in c: if isinstance(t,float) or isinstance(t,int): c2.append(t) print(c2)
2020-10-18
最新回答 / 慕无忌7227368
# Enter a coded = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}for key in d.keys(): for score in d[key]: print(key, score)
2020-10-18
# coding=utf-8
d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
template = "{}的第{}次成绩是{}分"
for key, value in d.items():
for index in range(len(value)):
print(template.format(key,index+1,value[index]))
d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
template = "{}的第{}次成绩是{}分"
for key, value in d.items():
for index in range(len(value)):
print(template.format(key,index+1,value[index]))
2020-10-18
a = 'python'
print 'hello,', a or 'world'
b = ''
print 'hello,', b or 'world'
a为有效字符串,即为true; 则 = true
b为空字符串,即为false; 则 = false
print 'hello,', a or 'world'
b = ''
print 'hello,', b or 'world'
a为有效字符串,即为true; 则 = true
b为空字符串,即为false; 则 = false
2020-10-15
def greet(c='World'):
print('hello'+','+c)
return
greet()
greet('sb')
print('hello'+','+c)
return
greet()
greet('sb')
2020-10-13
# coding=utf-8
#请分别使用循环和递归的形式定义函数,求出1~100的和。
#循环
def sum(n):
i=0
s=0
while i<=n:
s=s+i
i=i+1
print(s)
return
sum(100)
#递归
def he(n):
x=0
if n==1:
x=n
else:
x=he(n-1)+n
return x
print(he(100))
#请分别使用循环和递归的形式定义函数,求出1~100的和。
#循环
def sum(n):
i=0
s=0
while i<=n:
s=s+i
i=i+1
print(s)
return
sum(100)
#递归
def he(n):
x=0
if n==1:
x=n
else:
x=he(n-1)+n
return x
print(he(100))
2020-10-13
# coding=utf-8
def sub_sum(L):
y=0
j=0
i=0
while i<len(L):
if i%2==0:
y=y+L[i]
else:
j=j+L[i]
i=i+1
print(y,j)
return
sub_sum([1,2,3,4])
def sub_sum(L):
y=0
j=0
i=0
while i<len(L):
if i%2==0:
y=y+L[i]
else:
j=j+L[i]
i=i+1
print(y,j)
return
sub_sum([1,2,3,4])
2020-10-13