美文网首页
Python-04题

Python-04题

作者: AoEliauk | 来源:发表于2020-08-06 14:49 被阅读0次

Question:

>Write a program which accepts a sequence of comma-separated numbers from console and generate a list and a tuple which contains every number.Suppose the following input is supplied to the program:34,67,55,33,12,98

>Then, the output should be:

['34', '67', '55', '33', '12', '98']

('34', '67', '55', '33', '12', '98')

Hints:

>In case of input data being supplied to the question, it should be assumed to be a console input.tuple() method can convert list to tuple

Solution:

split() 通过指定分隔符对字符串进行切片,语法:str.split(str="", num=string.count(str))

str -- 分隔符,默认为所有的空字符,包括空格、换行(\n)、制表符(\t)等。

num -- 分割次数。默认为 -1, 即分隔所有。

1)由列表转成元组

program result

2)直接打印列表和元组

program result

相关文章

网友评论

      本文标题:Python-04题

      本文链接:https://www.haomeiwen.com/subject/ngtsrktx.html