集合

 #!/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. 洛谷P3193 GT考试 kmp+矩阵优化dp

    题意 求\(N\)位数字序列(可以有前导0)中不出现某\(M\)位子串的个数,模\(K\). \(N<=10^9,M<=20,K<=1000\) 分析 设\(dp[i][j]\)表示 ...

  2. FTP服务器安装配置

    1.安装:yum install vsftpd -y 2.修改配置文件:cd /etc/vsftpd/ cat vsftpd.conf | grep -Ev '^$|^#' listen_port= ...

  3. Loooooooooooooooong time no see!

    好久没来啦~去年这会一口气写了好多,是因为即将离职,在公司闲的没事,再加上也积累了一些东西想分享. 最近有个朋友给我私信求助,才又想起这里.这快一年时间,又学习了不少东西.从何写起呢,哈哈,不知道啊~ ...

  4. jQuery的replaceWith()函数用法详解

    replaceWith,替换元素 replaceWith() 方法将选择的元素的内容替换为其他内容. 我们先在先看一个实例 <!DOCTYPE html> <html> < ...

  5. [科普] CPU, GPU, TPU的区别

    Google Cloud 原文链接:https://cloud.google.com/blog/products/ai-machine-learning/what-makes-tpus-fine-tu ...

  6. JavaWeb-SpringBoot(抖音)_一、抖音项目制作

    JavaWeb-SpringBoot(抖音)_一.抖音项目制作 传送门 JavaWeb-SpringBoot(抖音)_二.服务器间通讯 传送门 JavaWeb-SpringBoot(抖音)_三.抖音项 ...

  7. UDP和TCP浅析

    UDP协议全称是用户数据报协议,在网络中它与TCP协议一样用于处理数据包,是一种无连接的协议. 在选择使用协议的时候,选择UDP必须要谨慎.在网络质量令人十分不满意的环境下,UDP协议数据包丢失会比较 ...

  8. Zookeeper 安装及命令行操作

    [参考文章]:[分布式]Zookeeper使用--命令行 [参考文章]:zookeeper的数据模型 [参考文章]:zookeeper ACL使用 1. 安装包下载 官方下载地址 选择一个具体的版本进 ...

  9. Linux 多线程按照线程顺序打印字符

    #include <stdio.h> #include <pthread.h> #include <unistd.h> ; pthread_mutex_t mute ...

  10. 关于colab的一些技巧

    1.指定工作文件夹(运行可以相对路径!) # 指定当前的工作文件夹 import os # 此处为google drive中的文件路径,drive为之前指定的工作根目录,要加上 os.chdir(&q ...