集合

 #!/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基础(集合、函数)的更多相关文章

  1. Python学习day04 - Python基础(2)数据类型基础

    <!doctype html>day04 - 博客 figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { ...

  2. Python学习day11-函数基础(1)

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  3. python学习博客地址集合。。。

    python学习博客地址集合...   老师讲课博客目录 http://www.bootcdn.cn/bootstrap/  bootstrap cdn在线地址 http://www.cnblogs. ...

  4. Python学习课程零基础学Python

    python学习课程,零基础Python初学者应该怎么去学习Python语言编程?python学习路线这里了解一下吧.想python学习课程?学习路线网免费下载海量python教程,上班族也能在家自学 ...

  5. Python学习day16-模块基础

    <!doctype html>day16 - 博客 figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { ...

  6. Python学习day12-函数基础(2)

    <!doctype html>day12博客 figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { pos ...

  7. Python学习笔记之基础篇(-)python介绍与安装

    Python学习笔记之基础篇(-)初识python Python的理念:崇尚优美.清晰.简单,是一个优秀并广泛使用的语言. python的历史: 1989年,为了打发圣诞节假期,作者Guido开始写P ...

  8. python学习日记(基础数据类型及其方法01)

    数字 int 主要是用于计算的,常用的方法有一种 #既十进制数值用二进制表示时,最少使用的位数i = 3#3的ASCII为:0000 0011,即两位 s = i.bit_length() print ...

  9. python学习6—数据类型之集合与字符串格式化

    python学习6—数据类型之集合与字符串格式化 1. 使用id()可以查看一个变量的内存地址: name = 'alex' id(name) 2. 进制转换 十进制转换为二进制等: a = 10 # ...

  10. Python学习day05 - Python基础(3) 格式化输出和基本运算符

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

随机推荐

  1. BFS解决九宫重排问题

    问题 1426: [蓝桥杯][历届试题]九宫重排 时间限制: 1Sec 内存限制: 128MB 提交: 215 解决: 47 题目描述 如下面第一个图的九宫格中,放着  1~8  的数字卡片,还有一个 ...

  2. ssh以及双机互信

    当我们要远程到其他主机上面时就需要使用ssh服务了. 我们就来安装一下sshd服务以及ssh命令的使用方法. 服务安装: 需要安装OpenSSH 四个安装包: 安装包: openssh-5.3p1-1 ...

  3. koa 项目实战(四)注册接口和调试工具(postman)

    1.安装模块 npm install koa-bodyparser --save npm install bcryptjs --save 2.引入模块 根目录/app.js const bodyPar ...

  4. 互操作性 a C++ library which enables seamless interoperability between C++ and the Python programming language

    https://zh.wikipedia.org/wiki/互操作性 就软件而言,互操作性——这条术语用来描述的是不同的程序(programs)借助于同一套交换格式(exchange formats) ...

  5. 离线安装nuget包EPPlus

    1先去https://www.nuget.org/packages/EPPlus/4.1.0下载,epplus.4.1.0.nupkg 2找到本地文件位置:H:\DOWNLOAD\ 3在vs的程序包管 ...

  6. 链表反转 C++

    ListNode* reverse1(ListNode* pHead) { if(pHead == NULL) return NULL; ListNode * p1 = NULL; ListNode ...

  7. LC 656. Coin Path 【lock, Hard】

    Given an array A (index starts at 1) consisting of N integers: A1, A2, ..., AN and an integer B. The ...

  8. 代码实现将键盘录入的数据拷贝到当前项目下的text.txt文件中,键盘录入数据当遇到quit时就退出

    package com.looaderman.test; import java.io.FileNotFoundException; import java.io.FileOutputStream; ...

  9. CKeditor从Word粘贴格式问题

    在config.js中添加配置 config.pasteFromWordRemoveFontStyles = false;    config.pasteFromWordRemoveStyles = ...

  10. ACO 蚁群算法(算法流程,TSP例子解析)

    算法 计算机 超级计算 高性能 科学探索 1. 算法背景——蚁群的自组织行为特征 高度结构化的组织——虽然蚂蚁的个体行为极其简单,但由个体组成的蚁群却构成高度结构化的社会组织,蚂蚁社会的成员有分工,有 ...