python编程题?

2025-04-28 17:00:25
推荐回答(5个)
回答1:

split()方法是通过指定分隔符对字符串进行切片,然后返回分割后的字符串列表

s. split(",")

输出是:
>>>["apple","peach","banana","pear"]

回答2:

s='apple,peach,banana,peach,pear'

sub='peach'

>>>s.find(sub) ##返回子串第一个字符出现的位置
6

回答3:

对不起,你的问题我不知道怎么回答。凑热闹的人太多了,我们都可以接受的

回答4:

['apple','peach','banana','pear']

回答5:

mons = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

def get_days(mon, day):

if mon == 1:

return mons[0], day

else:

count = sum(mons[:mon-1])

count = count + day

return mons[mon - 1], count

mon = int(input("请输入月份:"))

day = int(input("请输入号数:"))

result = get_days(mon, day)

print("{}月有{}天。".format(mon, result[0]))

print("{}月{}号是该年的第{}天".format(mon, day, result[1]))