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- ...
随机推荐
- MessagePack Jackson 数据大小
我们在使用 MessagePack 对 List 对象数据进行序列化的时候,发现序列化以后的二进制数组数据偏大的情况. 请注意,不是所有的 List 对象都会出现这种情况,这个根据你 List 对象中 ...
- js保留二位小数
js保留小数常用有三种方法,可根据实际情况选择 方法一:使用toFixed保留两位小数 自带四舍五入与补位 var num1 = 55.3715; console.log(num1.toFixed(2 ...
- 关于数据上传阿里云MaxCompute调研
1.背景 当前的数据存储基于mysql库表存储形式,目前已经无法满足愈加增大的数据存储需求,新项目基于Maxcompute数据仓库架构,需要将统计日志上传Maxcompute,本文对Maxcomput ...
- oracle中监听程序当前无法识别连接描述符中请求服务 的解决方法
早上同事用PL/SQL连接虚拟机中的Oracle数据库,发现又报了“ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务”错误,帮其解决后,发现很多人遇到过这样的问题,因此写着这里. ...
- Mybatis框架学习1:入门
一框架介绍 1.Mybatis介绍 MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google c ...
- 发送http请求和https请求的工具类
package com.haiyisoft.cAssistant.utils; import java.io.IOException;import java.util.ArrayList; impor ...
- 按下home键,重新打开,应用重启
其实不是重启,只是重新打开了luncher的那个activity.只要通过判断把它finish,就会显示按下home键前的页面. 解决方法: 在重启的页面中加入一下代码,注意加在setContentV ...
- Centos7.4 yum 安装MariaDB
#系统及版本选择:https://downloads.mariadb.org/mariadb/repositories/#mirror=tunavim /etc/yum.repos.d/MariaDB ...
- Selenium 2自动化测试实战30(unittest补充)
unittest补充 1.用例执行的顺序 #test.py #coding:utf-8 from Demo1 import Count import unittest class TestBdd(un ...
- ojdbc15-10.2.0.4.0.jar maven 引用报错 Dependency 'com.oracle:ojdbc15:10.2.0.4.0' not found
ojdbc15-10.2.0.4.0.jar maven 引用报错 问题现象 在 Maven 工程中引用 ojdbc15-10.2.0.4.0.jar 报错,报错信息:Dependency 'com. ...