zoukankan      html  css  js  c++  java
  • python——列表&字符串互相转换方法小结

     字符串(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

    待更新……

  • 相关阅读:
    编程学习杂烩
    设计模式
    redis
    H5
    Java
    db工具
    python + pip
    mysql
    Spring Security
    Spring Cloud Gateway
  • 原文地址:https://www.cnblogs.com/bigtreei/p/7840753.html
Copyright © 2011-2022 走看看