tup=("")
string=""
list1=[]
for i in range(100,1000):
A=str(i)[0]
B=str(i)[1]
C=str(i)[2]
if int(A)**3+int(B)**3+int(C)**3==i:
list1.append(str(i))#字符串转换成列表,并添加新的元素
print(",".join(list1))#列表重新转换成字符串,并打印
python字符串与列表的相互转换
学习内容:
1.字符串转列表
2.列表转字符串
1. 字符串转列表
str1 = "hi hello world" print(str1.split(" "))
输出:
['hi', 'hello', 'world']
2. 列表转字符串
l = ["hi","hello","world"] print(" ".join(l))
输出:
hi hello world
学习内容:
1.字符串转列表
2.列表转字符串
1. 字符串转列表
str1 = "hi hello world" print(str1.split(" "))
输出:
['hi', 'hello', 'world']
2. 列表转字符串
l = ["hi","hello","world"] print(" ".join(l))
输出:
hi hello world