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 ...
随机推荐
- shell统计mysql当前连接数
[root@push-- scripts]# mysql -S /var/lib/mysql//mysql.sock -uroot -phlsms_push_Zaq1xsw@ -e "sho ...
- python算法(一)基本知识&冒泡排序&选择排序&插入排序
本节内容: 算法基本知识 冒泡排序 选择排序 插入排序 1. 算法基本知识 1.1 什么是算法? 算法(algorithm):就是定义良好的计算过程,他取一个或一组的值为输入,并产生出一个或一组值作为 ...
- associate.py 源代码 及 使用方法
ORB_SLAM2运行RGBD数据集需要使用图片序列信息 使用以下代码进行汇集: #!/usr/bin/python # Software License Agreement (BSD License ...
- 拦截器HandlerInterceptor内部也可以注入bean,代码纠正补充
原文地址https://www.jianshu.com/p/890c23a1b3d7 原文内容 1.拦截器内无法通过SpringBean的方式注入LoggerJPA,我只能通过另外一种形式. priv ...
- UVA-10480-Sabotage(最大流最小割,打印路径)
链接: https://vjudge.net/problem/UVA-10480 题意: The regime of a small but wealthy dictatorship has been ...
- C语言中time函数和localtime获取系统时间和日期
可以通过time()函数来获得计算机系统当前的日历时间(Calendar Time),处理日期时间的函数都是以本函数的返回值为基础进行运算. 1. time 函数 返回1970-1-1, 00:00: ...
- Electron开发使用Vue Devtools
转自 [https://orchidflower.oschina.io/2017/03/29/Using-Vue-Devtools-in-Electron/] 2.2 安装步骤 首先在Chrome中安 ...
- 【webpack4】webpack4配置需要注意的问题
需要注意的知识: 要全局安装webpack以及webpack cli,否则不能使用webpack指令 npm install webpack -g npm install webpack-cli -g ...
- Maven Waring : GroupId is duplicate of parent groupId 和 Version is duplicate of parent version
问题描述: 新项目在创建的时候,因为用到了分模块的,所以导致子模块的pom文件,报了 如下警告: 解决办法: 直接 Window --> Preferences --> Maven -- ...
- tomcat8 的优化
1.下载tomcat8 2.配置 修改tomcat_user.xml,配置管理用户(设置角色,和用户密码) <role rolename="manager"/> < ...