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 ...
随机推荐
- php strip_tags() 函数去除 HTML、XML 以及 PHP 的标签。
strip_tags() 函数剥去 HTML.XML 以及 PHP 的标签.strip_tags(string,allow)参数 描述string 必需.规定要检查的字符串.allow ...
- PHP判断邮箱地址是否合法的正则表达式
PHP判断邮箱地址是否合法的正则表达式: function checkEmail($inAddress){ return (preg_match("/^([a-zA-Z0-9_-])+@([ ...
- web框架-(七)Django补充---models进阶操作及modelform操作
通过之前的课程我们可以对于Django的models进行简单的操作,今天了解下进阶操作和modelform: 1. Models进阶操作 1.1 字段操作 AutoField(Field) - int ...
- [易学易懂系列|rustlang语言|零基础|快速入门|(3)|所有权Ownership]
今天我们来讲讲rust最难,也是最重要的概念: Ownership,Borrowing,Lifetimes 首先我们来看看:ownership(所有权) 我们来看看下面的代码: let a = [1, ...
- ubuntu 添加新用户并赋予root权限
1 sudo adduser wolbo 2 sudo vim /etc/sudoers root ALL=(ALL) ALLwolbo ALL=(ALL) ALL wolbo ALL=(ALL) N ...
- python 后台 安装 富文本编辑
前言 当然需要安装一些后台只能输入一些文本编辑器,不然这样多少不美观呀 当然python 有 safe 可以把后台的标签转换 , 还有 striptags 这个是换成html 格式的,但不会加粗或 ...
- c# linq 分组groupby
转载: https://www.cnblogs.com/cncc/p/9846390.html 一.先准备要使用的类: 1.Person类: class Person { public string ...
- 在线PDF的实现 纯js
/// <summary> /// 使用微软的TransmitFile下载文件 /// </summary> /// <param name="filePath ...
- Qt新建工程
1.基本步骤 (1)Qt Quick Project是开发QML语言的: (2)Qt Widget Project是基于部件的开发,一种是PC的Qt Gui Application,一种是手机的Mob ...
- sh_04_第1个函数改造
sh_04_第1个函数改造 name = "小明" # say_hello() # Python 解释器知道下方定义了一个函数 def say_hello(): "&qu ...