Python学习【day04】- Python基础(集合、函数)
集合
#!/usr/bin/env python
# -*- coding:utf8 -*- # set集合 只可放不可变的数据类型,本身是可变数据类型,无序 # s = {1,2,3,[1,2,3],"abc",{'k':'v'},(1,2,3,)}
s = {1,2,3,"abc",(1,2,3,)}
print(s) # 拷贝
ss = s.copy()
print(ss) # 添加, 一次只可添加单个元素,若参数为可迭代类型 则当作整个元素添加
s.add("")
print(s) # 清除
s.clear()
print(s) s1 = {"a", "b", "c"}
s2 = {"b", "c", "d"} # 获取差集,参数只可为可迭代参数类型,可使用"-"代替
s = s1.difference(s2)
print(s, s1, s2, sep="\t")
print(s1 - s2) # 获取差集 并更新原来的集合
# s1.difference_update(["a", "b"])
# print(s1) # 移除节点信息 若节点不存在 不做任何处理
# s1.discard("a")
# print(s1)
# s1.discard("d")
# print(s1) # 交集 &
s = s1.intersection(s2)
print(s)
print(s1&s2) # 获取交集并更新
# s1.intersection_update("a")
# print(s1) # 两个集合是否有一个为空
v = set().isdisjoint({})
print(v) # s1是否为传入参数的子集
v = s1.issubset("abc")
print(v) # s1是否为传入参数的父级
v = s1.issuperset("abcd")
print(v) # 删除 随机
# s1.pop()
# print(s1) # 删除集合中的一个元素 若元素不存在则报错
# s1.remove("a")
# print(s1) print(s1)
# 交叉补集 "^" 获取不是两个集合共有的
s = s1.symmetric_difference(s2)
print(s)
print(s1^s2)
# 获取交叉补集并更新
# s1.symmetric_difference_update(s2)
# print(s1) # 并集 "|"
s = s1.union(s2)
print(s)
print(s1|s2) # 添加 可批量添加
s1.update(["ef", "gg"])
print(s1)
函数
#!/usr/bin/env python
# -*- coding:utf8 -*- # def test() :
# print("test Method")
# test() """
同名函数 后面的会覆盖前面的
"""
def test(x) :
print(x)
# test()
test(1) """
位置优先级要高于参数名赋值
"""
def test(x, y, z) :
print(x)
print(y)
print(z)
test(1,2,3)
test(x=1,z=2,y=4)
test(1,z=2,y=8)
# test(1,x=1,y=1,z=3) #报错 """
* 相当于列表 可传入多个值
"""
def test(x, *y) :
print(x)
print(*y)
test("a", ["bdc", "aaa"], ["a", "b"]) """
** 相当于字典
*类型参数 必须在 **类型参数前
必传参数不可当作最后一个参数传入
"""
def test(x, *y, **z) :
print(x)
print(y)
print(z, z.get("k"))
test(1,1,2,{'k':'v'},k=1) # def test(x, **y, *z) :
# pass # def test (*x, **y, z) :
# pass #必须指定以字典方式传入y值
def test(*x, y, **z) :
print("Method")
print(x)
print(y)
print(z)
pass
# test(1,1,1,y=1,y=2)
test(1,1,1,d=1,y=2)
Python学习【day04】- Python基础(集合、函数)的更多相关文章
- Python学习day04 - Python基础(2)数据类型基础
<!doctype html>day04 - 博客 figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { ...
- Python学习day11-函数基础(1)
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
- python学习博客地址集合。。。
python学习博客地址集合... 老师讲课博客目录 http://www.bootcdn.cn/bootstrap/ bootstrap cdn在线地址 http://www.cnblogs. ...
- Python学习课程零基础学Python
python学习课程,零基础Python初学者应该怎么去学习Python语言编程?python学习路线这里了解一下吧.想python学习课程?学习路线网免费下载海量python教程,上班族也能在家自学 ...
- Python学习day16-模块基础
<!doctype html>day16 - 博客 figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { ...
- Python学习day12-函数基础(2)
<!doctype html>day12博客 figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { pos ...
- Python学习笔记之基础篇(-)python介绍与安装
Python学习笔记之基础篇(-)初识python Python的理念:崇尚优美.清晰.简单,是一个优秀并广泛使用的语言. python的历史: 1989年,为了打发圣诞节假期,作者Guido开始写P ...
- python学习日记(基础数据类型及其方法01)
数字 int 主要是用于计算的,常用的方法有一种 #既十进制数值用二进制表示时,最少使用的位数i = 3#3的ASCII为:0000 0011,即两位 s = i.bit_length() print ...
- python学习6—数据类型之集合与字符串格式化
python学习6—数据类型之集合与字符串格式化 1. 使用id()可以查看一个变量的内存地址: name = 'alex' id(name) 2. 进制转换 十进制转换为二进制等: a = 10 # ...
- Python学习day05 - Python基础(3) 格式化输出和基本运算符
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
随机推荐
- hdu 5533 正n边形判断 精度处理
Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- 1012 最大公约数和最小公倍数问题 2001年NOIP全国联赛普及组
1012 最大公约数和最小公倍数问题 2001年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 题目描述 Description 输入二个 ...
- python 多线程实现循环打印 abc
python 多线程实现循环打印 abc 好久没写过python了, 想自己实践一下把 非阻塞版 import threading import time def print_a(): global ...
- zabbix服务端接收的数据类型,便于编写脚本向服务端提交数据
1.数据类型1:zabbix_agent执行脚本提交字典 UserParameter=tcp_port_listen,/usr/local/zabbix/share/script/get_game_p ...
- sqoop数据导出
1.将oracle的jdbc的jar包copy到sqoop的lib目录下 2. sqoop export --connect jdbc:oracle:thin:@XXXXX:1521:TMDM --u ...
- Rust格式化输出
打印操作由 https://doc.rust-lang.org/std/fmt/ 里面所定义的一系列宏来处理,包括: format!:将格式化文本写到字符串(String).(译注:字符串是返 回值不 ...
- Springboot集成MongoDB实现CRUD
特别提示:本人博客部分有参考网络其他博客,但均是本人亲手编写过并验证通过.如发现博客有错误,请及时提出以免误导其他人,谢谢!欢迎转载,但记得标明文章出处:http://www.cnblogs.com/ ...
- [转]基于java的程序OutOfMemory问题的解决及Xms/Xmx/Xss的解释和应用
长期以来一直都是做java应用的开发,所使用的开发工具基本上也都是基于java的,经常用的有eclipse, netbeans, ant, maven, cruisecontrol, tomcat, ...
- iOS真机调试之免费预配(Free provisioning)
免费预配允许开发者在不加入Applec Developer Program的情况下,可以发布和测试App 注意:免费预配(Free Provisioning)与自动预配(Auto Provisioni ...
- Web存储机制—sessionStorage,localStorage使用方法
Web存储机制,在这里主要聊有关于Web Storage API提供的存储机制,通过该机制,浏览器可以安全地存储键值对,比使用cookie更加直观.接下来简单的了解如何使用这方面的技术. 基本概念 W ...