[Python] python中数组,元组,字典和字符串之间的转换 →→→→→进入此内容的聊天室

来自 , 2020-10-01, 写在 Python, 查看 105 次.
URL http://www.code666.cn/view/8cea559c
  1. >>> mytuple = (1,2,3)
  2. >>> print list(mytuple)           # Tuple to list
  3. [1, 2, 3]
  4. >>>
  5. >>> mylist = [1,2,3]              # List to tuple
  6. >>> print tuple(mylist)
  7. (1, 2, 3)
  8. >>>
  9. >>> mylist2 = [ ('blue',5), ('red',3), ('yellow',7) ]
  10. >>> print dict(mylist2)           # List to dictionnary
  11. {'blue': 5, 'yellow': 7, 'red': 3}
  12. >>>
  13. >>> mystring = 'hello'
  14. >>> print list(mystring)          # String to list
  15. ['h', 'e', 'l', 'l', 'o']
  16. >>>
  17. >>> mylist3 = ['w','or','ld']
  18. >>> print ''.join(mylist3)        # List to string
  19. world
  20. >>>
  21. #//python/834

回复 "python中数组,元组,字典和字符串之间的转换"

这儿你可以回复上面这条便签

captcha