python3 基本数据类型_2
#!/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的更多相关文章
- Python3 基本数据类型注意事项
Python3 基本数据类型 教程转自菜鸟教程:http://www.runoob.com/python3/python3-data-type.html Python中的变量不需要声明.每个变量在使用 ...
- Python3 的数据类型
Python3 的数据类型 整形,浮点型,布尔类型 类型转换 int() 整形 采用截断的方式即向下取整,比如 a=5.5 int (a) 返回值为5 怎样才能使int()按照"四舍五入&q ...
- Python3 常见数据类型的转换
Python3 常见数据类型的转换 一.数据类型的转换,你只需要将数据类型作为函数名即可 OCP培训说明连接:https://mp.weixin.qq.com/s/2cymJ4xiBPtTaHu16H ...
- 3. Python3 基本数据类型
Python3 基本数据类型 Python 中的变量不需要声明.每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建. 在 Python 中,变量就是变量,它没有类型,我们所说的"类型& ...
- python003 Python3 基本数据类型
Python3 基本数据类型Python 中的变量不需要声明.每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建.在 Python 中,变量就是变量,它没有类型,我们所说的"类型&qu ...
- 【Python学习】Python3 基本数据类型
参考学习地址:https://www.runoob.com/python3/python3-data-type.html Python3 基本数据类型 Python 中的变量不需要声明.每个变量在使用 ...
- Python3 基本数据类型
Python中的变量不需要声明,每个变量使用前必须赋值,变量赋值后才会被创建,在Python中变量就是变量,它没有类型.我们所说的"类型"是变量所指的内存中对象的类型. 等号(=) ...
- python3基本数据类型
python3的基本数据类型: Number(数字).String(字符串).List(列表).Tuple(元组).Set(集合).Dictionary(字典) 不可变数据类型(3 个):Number ...
- python3 bytes数据类型探讨
python3中str和bytes分开了,那么bytes与str之间到底是什么关系呢?下面从表现形式.处理方式.存储形式三个方面来阐述其区别 1. 在字符串前面加上b,就表示bytes数据类型 s1 ...
随机推荐
- Jmeter线程组间传递参数
现在做测试和以前不太一样了,以前只要站在一个用户的角度做端到端的UI测试就可以了,现在不会做接口测试,出去都不好意思和别人打招呼.那提到接口测试,就不得不提一下接口测试利器Jmeter,大家也都知道, ...
- Codeforces1204C. Anna, Svyatoslav and Maps (贪心 + Floyd)
题目链接:传送门 题目大意: 给出n<=100的有向图,和路径p,求p的最短子序列v,使得依次经过v中所有点的路径为p. 思路: 题意其实就是让我们求路径上的一些关键点v,对于所有的关键点:vi ...
- Python核心技术与实战——十二|Python的比较与拷贝
我们在前面已经接触到了很多Python对象比较的例子,例如这样的 a = b = a == b 或者是将一个对象进行拷贝 l1 = [,,,,] l2 = l1 l3 = list(l1) 那么现在试 ...
- Mac 升级python2.7 到 3.5
Mac 系统 OSX 10.12 以上 第1步:下载Python3.5 下载地址如下: Python3.5 第二步:安装python 3.50 点击下载好的pkg文件进行安装,安装完成之后,pyt ...
- 【leetcode】Sliding Puzzle
题目如下: On a 2x3 board, there are 5 tiles represented by the integers 1 through 5, and an empty square ...
- 【leetcode】Monotone Increasing Digits
Given a non-negative integer N, find the largest number that is less than or equal to N with monoton ...
- IntelliJ IDEA 2019.3激活破解教程(亲测有效,可激活至 2089 年)
IntelliJ IDEA 2019.3激活破解教程(亲测有效,可激活至 2089 年) 所有软件安装位置,作者均在无中文.无空格目录下进行操作的 IntelliJ IDEA 2019.3激活破解教程 ...
- Chrome开发者工具面板 F12 调试大全 记录
面板上包含了Elements面板.Console面板.Sources面板.Network面板.Timeline面板.Profiles面板.Application面板.Security面板.Audits ...
- Python连接MySQL之Python库pymysql
连接数据库 pymysql连接数据库的方式和使用sqlite的方式基本相同: 使用connect创建连接对象 connect.cursor创建游标对象,SQL语句的执行基本都在游标上进行 cursor ...
- XML 验证
拥有正确语法的 XML 被称为“形式良好”的 XML. 通过 DTD 验证的 XML 是“合法”的 XML. 形式良好的 XML 文档 “形式良好”或“结构良好”的 XML 文档拥有正确的语法. “形 ...