python-字符串转换为列表、元组

输入一个字符串,转换成列表、元组,请在下面标注序号的位置填写程序

输入一串字符,比如‘I am a student’,

tempStr = input()

(1)转换为列表1:[‘I’, ‘am’, ‘a’, ‘student’]

list1=tempStr.split(" ")
print(list1)

(2)转换为元组1: (‘I’, ‘am’, ‘a’, ‘student’)

tuple1=tuple(list1) 
print(tuple1)

(3)转换为列表2:[‘I’, ’ ', ‘a’, ‘m’, ’ ', ‘a’, ’ ', ‘s’, ‘t’, ‘u’, ‘d’,
‘e’, ‘n’, ‘t’]

print(list(tuple(tempStr)))

你可能感兴趣的:(#,案例,#,python基础知识)