字符串(str)转列表(list)

转换方法:str.split()

str = 'zhu gao chao'
print(str.split(' '))    # 用split进行转换    str——>list

执行结果:
['zhu', 'gao', 'chao']

Process finished with exit code 0

 

列表(list)转字符串(str)

转换方法: str.join(list)

lis = ['zhu', 'gao', 'chao']
str = ''.join(lis)  # 无缝拼接
print(str)

#执行结果:
zhugaochao

Process finished with exit code 0



lis = ['zhu', 'gao', 'chao']
str = ''.join(lis)  # 用 , 拼接
print(str)

#执行结果:
zhu,gao,chao

Process finished with exit code 0

 

待更新……

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2021-09-14
猜你喜欢
  • 2021-05-17
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案