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- ...
随机推荐
- POJ 2109 Power of Cryptography 数学题 double和float精度和范围
Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21354 Accepted: 107 ...
- jquery文章链接
好文链接 1.jQuery是js的一个库,封装了js中常用的逻辑: 2.调用jQuery: (1).本地调用,在script标签的src属性里写上jQuery文件的地址. (2).使用CDN调用jQu ...
- Python基础之赋值运算符
如下图所示,假设变量a = 10, b = 20
- Spring Boot教程(三十五)使用MongoDB数据库(1)
MongoDB简介 MongoDB是一个基于分布式文件存储的数据库,它是一个介于关系数据库和非关系数据库之间的产品,其主要目标是在键/值存储方式(提供了高性能和高度伸缩性)和传统的RDBMS系统(具有 ...
- Ubuntu16.04安装nginx(并启用SSL)
一.安装环境介绍 需要预先安装gcc,通常ubuntu默认自带,所以默认已经有这个环境了,后续步骤默认是使用root账户进行的 二.下载及安装nginx相关组件 1.进入任意目录,我选用的是通常选用的 ...
- Mac securecrt 破解
今天花了好长的时间终于在Mac上把SecureCRT安装成功了,网上教程大多没有截图,破解关键步骤含糊,现在把详细的破解过程和SecureCRT使用教程分享给大家.最后把参考的博客连接附在最下方. ...
- CentOS 7下使用Apache2部署Django项目,解决文件名中含有中文报错的问题
系统版本: CentOS 7.3Apache 2.4 Django 1.11 问题描述 Django项目涉及上传操作,上传文件名称含有中文,若使用runserver启动服务,没有问题!若将Django ...
- [学习笔记] Tangent Distance
Tangent Distance 简介 切空间距离可以用在KNN方法中度量距离,其解决的是图像经过有限变换之后还能否被分类正确,例如.对一张数字为5的手写数字图片,将其膨胀后得到图像p1,此时KNN还 ...
- LC 759. Employee Free Time 【lock, hard】
We are given a list schedule of employees, which represents the working time for each employee. Each ...
- 自定义Dialog布局的弹窗功能的简单实现
package com.loaderman.dialogdemo; import android.os.Bundle; import android.support.v7.app.AlertDialo ...