#!/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. C语言——枚举类型用法

    1.枚举的定义 enum 枚举名{ 枚举元 素1,枚举元素2,枚举元素3...}: 2.使用枚举类型的好处 增加程序的可读性,我们都知道在计算机中所有信息都是用二进制来表示的,如果你用二进制来表示某件 ...

  2. bat 感想

    用bat做了个跨版本更新包的生成脚本,由于之前都是写一些很简单bat,或者python里使用windows命令,所以纯用bat做这个东西,还是有点复杂的. 过程中遇到很多问题,主要是参数太多,变量的使 ...

  3. mysql5.7.26做主从复制配置

    一.首先两台服务器安装好mysql数据库环境 参照linux rpm方式安装mysql5.1 https://www.cnblogs.com/sky-cheng/p/10564604.html 二.主 ...

  4. Flume 实时获取日志内容插入MySQL

    https://www.jianshu.com/p/22e6133649ca 采用链接的方法试了一下,好像不成功,问题出在 channel.take();   //获取出来的Event为空,不知道为啥

  5. ESP8266WiFiGeneric---通用库--事件和配置

    ESP8266WiFiSTAClass .ESP8266WiFiScanClass .ESP8266WiFiAPClass 可以访问 ESP8266WiFiGenericClass的private和p ...

  6. tf.InteractiveSession() 和 tf.Session() 的区别

    tf.InteractiveSession():它能让你在运行图的时候,插入一些计算图,这些计算图是由某些操作(operations)构成的.这对于工作在交互式环境中的人们来说非常便利,比如使用IPy ...

  7. sh_10_分隔线模块

    sh_10_分隔线模块 def print_line(char, times): """打印单行分隔线 :param char: 分隔字符 :param times: 重 ...

  8. sh_07_continue

    sh_07_continue i = 0 while i < 10: # continue 某一条件满足时,不执行后续重复的代码 # i == 3 if i == 3: # 注意:在循环中,如果 ...

  9. smarty笔记

    smarty 笔记display():把html包含进来然后用正则匹配php变量把匹配好的页面重新保存inclue载入刚才的保存的页面 1.smarty原理2.smarty安装3.smarty模板设计 ...

  10. [BZO3572][HNOI2014]世界树:虚树+倍增

    分析 思维难度几乎为\(0\)的虚树码农(并不)题. 代码 #include <bits/stdc++.h> #define rin(i,a,b) for(register int i=( ...