+ 1
Python exercise need explanations
Q: Write a Python program which accepts a sequence of comma-separated numbers from user and generate a list and a tuple with those numbers. Code: values = input("Input some comma seprated numbers : ") list = values.split(",") tuple = tuple(list) print('List : ',list) print('Tuple : ',tuple) Input some comma seprated numbers : 3,5,7,23 List : ['3', '5', '7', '23'] Tuple : ('3', '5', '7', '23') I understand how tuples function, can someone explain to me how lost was created in this exercise ?
4 Respostas
+ 2
My guess is split function returns list. :)
https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/ref_string_split.asp
+ 1
It is not recommended to use functions (e.g. list, tuple) as variable names as they can mess up with your code.
0
Thanks a lot that was really helpful
0
returns a list of strings after breaking the given string by the specified separator.
http://net-informations.com/JUMP_LINK__&&__python__&&__JUMP_LINK/file/split.htm