我有一个字符串:
countries = "India,Bangladesh,Srilanka,South Africa,Australia,Canada"
我需要从中获取一个数组:
countries = ["India","Bangladesh","Srilanka","South Africa","Australia","Canada"]
我怎么能这样做?
答案 0 :(得分:4)
使用split
方法:
countries = countries.split(",")
答案 1 :(得分:2)
试试这个:
countries = "India,Bangladesh,Srilanka,South Africa,Australia,Canada".split(',')