#!/usr/bin/python3

 #以下set,dict的方法py2无法运行

 #创建set 集合,使用大括号 { } 或者 set() 函数创建
#注意:创建一个空集合必须用 set() 而不是 { },因为 { } 是用来创建一个空字典
num1={1,2,3,4,5,6,5,6}
#打印集合,自动去重
print('num1 :', num1) if(9 in num1):
print('9 in num1')
else:
print('9 not in num1') num2={1,22,33,4,55} print('num2 :', num2)
#检查num1类型
print("type num1 :",type(num1))
print('num1-num2 差集 :', num1-num2)
print('num1|num2 并集 :' ,num1|num2)
print('num1&num2 交集 :' ,num1&num2)
print('num1^num2 不同时存在的元素 :' ,num1^num2) print('*'*60)
#字典用"{ }"标识,它是一个无序的键(key) : 值(value)对集合
#键(key)必须使用不可变类型
#在同一个字典中,键(key)必须是唯一的 dict1={'http':'www.cnblogs.com','sub2020':'p\/8006988.html'}
dict1['com']="sub2020"
print("dict1 :", dict1)
print("dict1 type :",type(dict1))
#打印字典的 键
print(dict1.keys())
#打印字典的 值
print(dict1.values()) #创建空字典
dict2={}
dict2['com']="sub2020"
dict2['']="a"
dict2[""]="b"
#经过几次分别赋值后,打印字典
print("dict2 :",dict2) #构造函数 dict() 可以直接从键值对序列中构建字典
dict3=dict([('a',1),('b',2),('c',3)])
dict4=dict(a=1,b=2,c=3)
dict5={x:x**2 for x in(2,3,4)}
print("dict3 :",dict3)
print("dict4 :",dict4)
print("dict5 :",dict5)

output

num1 : {1, 2, 3, 4, 5, 6}
9 not in num1
num2 : {1, 33, 4, 22, 55}
type num1 : <class 'set'>
num1-num2 差集 : {2, 3, 5, 6}
num1|num2 并集 : {1, 2, 3, 4, 5, 6, 33, 22, 55}
num1&num2 交集 : {1, 4}
num1^num2 不同时存在的元素 : {33, 2, 3, 22, 55, 5, 6}
************************************************************
dict1 : {'http': 'www.cnblogs.com', 'sub2020': 'p\\/8006988.html', 'com': 'sub2020'}
dict1 type : <class 'dict'>
dict_keys(['http', 'sub2020', 'com'])
dict_values(['www.cnblogs.com', 'p\\/8006988.html', 'sub2020'])
dict2 : {'com': 'sub2020', '': 'a', '': 'b'}
dict3 : {'a': 1, 'b': 2, 'c': 3}
dict4 : {'a': 1, 'b': 2, 'c': 3}
dict5 : {2: 4, 3: 9, 4: 16} ***Repl Closed***

python3 基本数据类型_2的更多相关文章

  1. Python3 基本数据类型注意事项

    Python3 基本数据类型 教程转自菜鸟教程:http://www.runoob.com/python3/python3-data-type.html Python中的变量不需要声明.每个变量在使用 ...

  2. Python3 的数据类型

    Python3 的数据类型 整形,浮点型,布尔类型 类型转换 int() 整形 采用截断的方式即向下取整,比如 a=5.5 int (a) 返回值为5 怎样才能使int()按照"四舍五入&q ...

  3. Python3 常见数据类型的转换

    Python3 常见数据类型的转换 一.数据类型的转换,你只需要将数据类型作为函数名即可 OCP培训说明连接:https://mp.weixin.qq.com/s/2cymJ4xiBPtTaHu16H ...

  4. 3. Python3 基本数据类型

    Python3 基本数据类型 Python 中的变量不需要声明.每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建. 在 Python 中,变量就是变量,它没有类型,我们所说的"类型& ...

  5. python003 Python3 基本数据类型

    Python3 基本数据类型Python 中的变量不需要声明.每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建.在 Python 中,变量就是变量,它没有类型,我们所说的"类型&qu ...

  6. 【Python学习】Python3 基本数据类型

    参考学习地址:https://www.runoob.com/python3/python3-data-type.html Python3 基本数据类型 Python 中的变量不需要声明.每个变量在使用 ...

  7. Python3 基本数据类型

    Python中的变量不需要声明,每个变量使用前必须赋值,变量赋值后才会被创建,在Python中变量就是变量,它没有类型.我们所说的"类型"是变量所指的内存中对象的类型. 等号(=) ...

  8. python3基本数据类型

    python3的基本数据类型: Number(数字).String(字符串).List(列表).Tuple(元组).Set(集合).Dictionary(字典) 不可变数据类型(3 个):Number ...

  9. python3 bytes数据类型探讨

    python3中str和bytes分开了,那么bytes与str之间到底是什么关系呢?下面从表现形式.处理方式.存储形式三个方面来阐述其区别 1. 在字符串前面加上b,就表示bytes数据类型 s1 ...

随机推荐

  1. 我所了解的https

    http大家多少都有些了解,毕竟要上网的话是肯定会接触到它的.http有个很明显的缺点,就是传输是明文的,很不安全.针对这个情况,就推出了https,也就是http+ssl/tls. 对于明文不安全的 ...

  2. pycharm 的一个小问题

    版本:PyCharm 2018.3.7 (Professional Edition) 这段时间用pycharm写python代码,运行网上copy的代码.报错了也就是少个模块或者Python2的语法在 ...

  3. Codeforces Round #575 (Div. 3) (A. Three Piles of Candies)(数学)

    A. Three Piles of Candies time limit per test1 second memory limit per test256 megabytes inputstanda ...

  4. SCC统计

    Kosoraju SCC总数及记录SCC所需要的最少边情况 #include<cstdio> ; ; ][N], nxt[][N], v[][N], ed, q[N], t, vis[N] ...

  5. JS获取当前日期和时间的方法,并按照YYYY-MM-DD格式化

    Js获取当前日期时间及其它操作 var myDate = new Date(); myDate.getYear();        //获取当前年份(2位) myDate.getFullYear(); ...

  6. for循环与内置方法详解

    ''' for循环与内置方法详解 ''' # 循环:重复(按照某种规律的)做一件事情 # lt = [1, 2, 3, 4] # # ind = 0 # # while True: # print(l ...

  7. python修炼之路——控制语句

    Python编程之print python2.x和python3.x的print函数区别:python3.x的print函数需要加括号(),python2.x可以不加. #-*- coding:utf ...

  8. Maven工程构建

    Maven 相关术语: 本地资源库:用来存储项目的依赖库,默认的文件夹是 “.m2” 目录 中央存储库: 用来下载所有项目的依赖库的默认位置 Maven pom.xml: 项目对象模型(Project ...

  9. 【NOIP2016提高组day1】†换教室

    题目 对于刚上大学的牛牛来说,他面临的第一个问题是如何根据实际情况申请合适的 课程. 在可以选择的课程中,有 2n 节课程安排在 n 个时间段上. 在第 i ( 1 ≤ i ≤ n )个 时间段上,两 ...

  10. LDA主题模型评估方法–Perplexity

    在LDA主题模型之后,需要对模型的好坏进行评估,以此依据,判断改进的参数或者算法的建模能力. Blei先生在论文<Latent Dirichlet Allocation>实验中用的是Per ...