zoukankan      html  css  js  c++  java
  • 组合数据类型综合练习

    1.组合数据类型练习:

    分别定义字符串,列表,元组,字典,集合,并进行遍历。

    字符串:

    >>> str = 'csdasd'
    >>> for i in str:
    	print(i)
    
    	
    c
    s
    d
    a
    s
    d
    

      

      

    列表:

    >>> ls = ['1','2','3','446']
    >>> for i in ls:
    	print(i)
    
    	
    1
    2
    3
    446
    

      

    元组:

    >>> turtle = ('da', 'ds', 'sd')
    >>> for i in turtle:
    	print(i)
    
    	
    da
    ds
    sd
    

      

    字典:

    >>> dict = {'Alice':'123', 'Bac':'113','Casd':'325'}
    >>> for i in dict:
    	print(i+':'+dict[i])
    
    	
    Alice:123
    Bac:113
    Casd:325
    

      

    集合:

    >>> b = set(['sd', 'fd', 'wqe'])
    >>> for i in b:
    	print(i)
    
    	
    fd
    sd
    wqe
    

      

    总结列表,元组,字典,集合的联系与区别。

    列表和元组可以说基本一样,不一样的是列表可以用extend、insert、pop、append来添加,插入,删除元素。

    而字典是以键值对来存放数据,集合却是相当于字典的键值“key”。

  • 相关阅读:
    自定义 mapper
    solr 服务搭建
    jedis 连接redis
    jedis 整合 Spring
    Redis 安装
    HttpClient 工具类
    springMvc 中返回字符串 乱码解决
    linux常用命令解析
    压缩jar包
    控制反转
  • 原文地址:https://www.cnblogs.com/-hjd/p/8626206.html
Copyright © 2011-2022 走看看