zoukankan      html  css  js  c++  java
  • Python数据类型

    #分别定义字符串。列表,元组,字典,集合,并进行遍历,总结列表元组,字典集合的联系与区别
    print("字符串")
    Strings="Hello World"
    for i in Strings:
        print(i)
    print("列表")
    lists=['michael','bob','mike','Tracy']
    for i in lists:
        print(i)
    print("元组")
    tup=('michael','mike',1,2,5)
    for i in tup:
        print(i)
    print('字典')
    dict = {'Alice': '2341', 'Beth': '9102', 'Cecil': '3258'}
    for key in dict:
        print(key,':',dict[key])
    print('集合')
    set=([1,2,3])
    for i in set:
        print(i)
    

     

    字符串
    H
    e
    l
    l
    o
     
    W
    o
    r
    l
    d
    列表
    michael
    bob
    mike
    Tracy
    元组
    michael
    mike
    1
    2
    5
    字典
    Alice : 2341
    Beth : 9102
    Cecil : 3258
    集合
    1
    2
    3
    
    Process finished with exit code 0
    

      

     列表与元组的区别与联系:Python的元组与列表类似,不同之处在于元组的元素不能修改。元组使用小括号,列表使用方括号。

     集合与字典的区别与联系:集合可以进行运算,而字典有一对一的对应关系。集合中的元素是唯一的。字典和系列都是没有序列的不可通过序列查找

  • 相关阅读:
    LeetCode Flatten Binary Tree to Linked List
    LeetCode Longest Common Prefix
    LeetCode Trapping Rain Water
    LeetCode Add Binary
    LeetCode Subsets
    LeetCode Palindrome Number
    LeetCode Count and Say
    LeetCode Valid Parentheses
    LeetCode Length of Last Word
    LeetCode Minimum Depth of Binary Tree
  • 原文地址:https://www.cnblogs.com/polvem/p/8624967.html
Copyright © 2011-2022 走看看