2019-05-21

------------------------

help(tuple)

-------------------------

Help on class tuple in module builtins:

class tuple(object)
|  tuple(iterable=(), /)
| 
|  Built-in immutable sequence.
| 
|  If no argument is given, the constructor returns an empty tuple.
|  If iterable is specified the tuple is initialized from iterable's items.
| 
|  If the argument is a tuple, the return value is the same object.
| 
|  Methods defined here:
| 
|  __add__(self, value, /)
|      Return self+value.
| 
|  __contains__(self, key, /)
|      Return key in self.
| 
|  __eq__(self, value, /)
|      Return self==value.
| 
|  __ge__(self, value, /)
|      Return self>=value.
| 
|  __getattribute__(self, name, /)
|      Return getattr(self, name).
| 
|  __getitem__(self, key, /)
|      Return self[key].
| 
|  __getnewargs__(self, /)
| 
|  __gt__(self, value, /)
|      Return self>value.
| 
|  __hash__(self, /)
|      Return hash(self).
| 
|  __iter__(self, /)
|      Implement iter(self).
| 
|  __le__(self, value, /)
|      Return self<=value.
| 
|  __len__(self, /)
|      Return len(self).
| 
|  __lt__(self, value, /)
|      Return self<value.
| 
|  __mul__(self, value, /)
|      Return self*value.
| 
|  __ne__(self, value, /)
|      Return self!=value.
| 
|  __repr__(self, /)
|      Return repr(self).
| 
|  __rmul__(self, value, /)
|      Return value*self.
| 
|  count(self, value, /)
|      Return number of occurrences of value.
| 
|  index(self, value, start=0, stop=9223372036854775807, /)
|      Return first index of value.
|     
|      Raises ValueError if the value is not present.
| 
|  ----------------------------------------------------------------------
|  Static methods defined here:
| 
|  __new__(*args, **kwargs) from builtins.type
|      Create and return a new object.  See help(type) for accurate signature.
---------------------------------------------------

# count() 计算某个元素在元组中出现的次数
tuple1 = (3,2,4,1,3,6)
print(tuple1.count(3))

-----------------------------------------------------

# index() 获取值在元组中的索引
tuple1 = (3,2,4,1,3,6)
print(tuple1.index(3))
print(tuple1.index(3,1,5))

---------------------------------------------------------

# clear() 清除整个字典   返回None
dict1 = {'a':1, 'b':2, 'c':3}
dict2 = dict1.copy()
print(dict2)

--------------------------------------------------------

# fromkeys() 按照指定的序列为键创建字典,值都是一样的
list1 = ['a', 'b', 'c']
dict1 = {}.fromkeys(list1)
dict2 = {}.fromkeys(list1, 3)
print(dict1,dict2)

---------------------------------------------------------

# get() 根据键获取指定的值    找不到的键如果没有默认值则返回默认值, 如果没默认值,则返回None
dict1 = {'a':1, 'b':2, 'c':3}
print(dict1.get('b'))
print(dict1.get('d'))
print(dict1.get('d', 4))

--------------------------------------

# items() 将字典变成类似于元组的形式方便遍历
dict1 = {'a':1, 'b':2, 'c':3}
for k,v in dict1.items():
    print(k,v)
for i in dict1.items():
    print(i)
   
print(dict1.items())

----------------------------------

# pop() 移除字典中指定元素  返回键所对应的值,如果键不存在,则返回默认值,如果键找不到,没有默认值,就会报错
dict1 = {'a':1, 'b':2, 'c':3}
print(dict1.pop('a'))
print(dict1)
print(dict1.pop('d', 4))
print(dict1.pop('d'))

----------------------------------

# popitem() 移除字典的键值时,返回移除的键和值
dict1 = {'d':4,'a':1, 'b':2, 'c':3 }
print(dict1.popitem())

------------------------------------

# update() 修改字典中的值
dict1 = {'d':4, 'a':1, 'b':2, 'c':3}
dict1.update({'a':3, 'b':4, 'e':6})
print(dict1)

------------------------------------

help(set)

-------------------------------------

Help on class set in module builtins:

class set(object)
|  set() -> new empty set object
|  set(iterable) -> new set object
| 
|  Build an unordered collection of unique elements.
| 
|  Methods defined here:
| 
|  __and__(self, value, /)
|      Return self&value.
| 
|  __contains__(...)
|      x.__contains__(y) <==> y in x.
| 
|  __eq__(self, value, /)
|      Return self==value.
| 
|  __ge__(self, value, /)
|      Return self>=value.
| 
|  __getattribute__(self, name, /)
|      Return getattr(self, name).
| 
|  __gt__(self, value, /)
|      Return self>value.
| 
|  __iand__(self, value, /)
|      Return self&=value.
| 
|  __init__(self, /, *args, **kwargs)
|      Initialize self.  See help(type(self)) for accurate signature.
| 
|  __ior__(self, value, /)
|      Return self|=value.
| 
|  __isub__(self, value, /)
|      Return self-=value.
| 
|  __iter__(self, /)
|      Implement iter(self).
| 
|  __ixor__(self, value, /)
|      Return self^=value.
| 
|  __le__(self, value, /)
|      Return self<=value.
| 
|  __len__(self, /)
|      Return len(self).
| 
|  __lt__(self, value, /)
|      Return self<value.
| 
|  __ne__(self, value, /)
|      Return self!=value.
| 
|  __or__(self, value, /)
|      Return self|value.
| 
|  __rand__(self, value, /)
|      Return value&self.
| 
|  __reduce__(...)
|      Return state information for pickling.
| 
|  __repr__(self, /)
|      Return repr(self).
| 
|  __ror__(self, value, /)
|      Return value|self.
| 
|  __rsub__(self, value, /)
|      Return value-self.
| 
|  __rxor__(self, value, /)
|      Return value^self.
| 
|  __sizeof__(...)
|      S.__sizeof__() -> size of S in memory, in bytes
| 
|  __sub__(self, value, /)
|      Return self-value.
| 
|  __xor__(self, value, /)
|      Return self^value.
| 
|  add(...)
|      Add an element to a set.
|     
|      This has no effect if the element is already present.
| 
|  clear(...)
|      Remove all elements from this set.
| 
|  copy(...)
|      Return a shallow copy of a set.
| 
|  difference(...)
|      Return the difference of two or more sets as a new set.
|     
|      (i.e. all elements that are in this set but not the others.)
| 
|  difference_update(...)
|      Remove all elements of another set from this set.
| 
|  discard(...)
|      Remove an element from a set if it is a member.
|     
|      If the element is not a member, do nothing.
| 
|  intersection(...)
|      Return the intersection of two sets as a new set.
|     
|      (i.e. all elements that are in both sets.)
| 
|  intersection_update(...)
|      Update a set with the intersection of itself and another.
| 
|  isdisjoint(...)
|      Return True if two sets have a null intersection.
| 
|  issubset(...)
|      Report whether another set contains this set.
| 
|  issuperset(...)
|      Report whether this set contains another set.
| 
|  pop(...)
|      Remove and return an arbitrary set element.
|      Raises KeyError if the set is empty.
| 
|  remove(...)
|      Remove an element from a set; it must be a member.
|     
|      If the element is not a member, raise a KeyError.
| 
|  symmetric_difference(...)
|      Return the symmetric difference of two sets as a new set.
|     
|      (i.e. all elements that are in exactly one of the sets.)
| 
|  symmetric_difference_update(...)
|      Update a set with the symmetric difference of itself and another.
| 
|  union(...)
|      Return the union of sets as a new set.
|     
|      (i.e. all elements that are in either set.)
| 
|  update(...)
|      Update a set with the union of itself and others.
| 
|  ----------------------------------------------------------------------
|  Static methods defined here:
| 
|  __new__(*args, **kwargs) from builtins.type
|      Create and return a new object.  See help(type) for accurate signature.
| 
|  ----------------------------------------------------------------------
|  Data and other attributes defined here:
| 
|  __hash__ = None

----------------------------------------

a = set()
print(a)
list1 = [1,2,3,4]
a = set(list1)
print(a)

--------------------------------------------

# add() 向集合中添加元素
set1 = {5,1,2,3,4,'b','u'}
set1.add(6)
print(set1)

--------------------------------

# clear()   清空集合
# copy()   复制集合
# pop()    随机弹出一个元素
a = {'a', 'b', 'f', 4}
a.pop()
print(a)

-----------------------------------

# remove 删除集合中的某个值,如果这个值不在集合中会报错
a = {'a', 'b', 'f', 4}
a.remove(4)
print(a)
a.remove(4)

-------------------------------------

# difference() 差集
# difference_update() 区别就是第一个返回一个新的集合,第二个把原来集合覆盖
set1 = {1,2,3,4,7}
set2 = {2,4,8,111,24}
set3 = set1.difference(set2)
print(set3)
print(set1)

------------------------------------------

Python---基础---dict_tuple_set的更多相关文章

  1. python之最强王者(2)——python基础语法

    背景介绍:由于本人一直做java开发,也是从txt开始写hello,world,使用javac命令编译,一直到使用myeclipse,其中的道理和辛酸都懂(请容许我擦干眼角的泪水),所以对于pytho ...

  2. Python开发【第二篇】:Python基础知识

    Python基础知识 一.初识基本数据类型 类型: int(整型) 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2147483648-2147483647 在64位 ...

  3. Python小白的发展之路之Python基础(一)

    Python基础部分1: 1.Python简介 2.Python 2 or 3,两者的主要区别 3.Python解释器 4.安装Python 5.第一个Python程序 Hello World 6.P ...

  4. Python之路3【第一篇】Python基础

    本节内容 Python简介 Python安装 第一个Python程序 编程语言的分类 Python简介 1.Python的由来 python的创始人为吉多·范罗苏姆(Guido van Rossum) ...

  5. 进击的Python【第三章】:Python基础(三)

    Python基础(三) 本章内容 集合的概念与操作 文件的操作 函数的特点与用法 参数与局部变量 return返回值的概念 递归的基本含义 函数式编程介绍 高阶函数的概念 一.集合的概念与操作 集合( ...

  6. 进击的Python【第二章】:Python基础(二)

    Python基础(二) 本章内容 数据类型 数据运算 列表与元组的基本操作 字典的基本操作 字符编码与转码 模块初探 练习:购物车程序 一.数据类型 Python有五个标准的数据类型: Numbers ...

  7. Python之路【第一篇】python基础

    一.python开发 1.开发: 1)高级语言:python .Java .PHP. C#  Go ruby  c++  ===>字节码 2)低级语言:c .汇编 2.语言之间的对比: 1)py ...

  8. python基础之day1

    Python 简介 Python是著名的“龟叔”Guido van Rossum在1989年圣诞节期间,为了打发无聊的圣诞节而编写的一个编程语言. Python为我们提供了非常完善的基础代码库,覆盖了 ...

  9. python基础之文件读写

    python基础之文件读写 本节内容 os模块中文件以及目录的一些方法 文件的操作 目录的操作 1.os模块中文件以及目录的一些方法 python操作文件以及目录可以使用os模块的一些方法如下: 得到 ...

  10. python基础之编码问题

    python基础之编码问题 本节内容 字符串编码问题由来 字符串编码解决方案 1.字符串编码问题由来 由于字符串编码是从ascii--->unicode--->utf-8(utf-16和u ...

随机推荐

  1. TypeScript快速笔记(二)

    1) TypeScript中的判断语句,可以使用非0值代表true.如: function add1(a: number, b?:number): number{ // 注意b是可选参数 consol ...

  2. (转)oracle触发器使用:after insert 与before insert的简单使用注意

    本文转载自:http://blog.csdn.net/kuangfengbuyi/article/details/41446125 创建触发器时,触发器类型为after insert , 在begin ...

  3. ArrayBlockingQueue 源码分析

    ArrayBlockingQueue ArrayBlockingQueue 能解决什么问题?什么时候使用 ArrayBlockingQueue? 1)ArrayBlockingQueue 是底层由数组 ...

  4. jenkins打包ios 报错rror: No signing certificate "iOS Distribution" found: No "iOS Distribution...

    错误提示如图: error: No signing certificate "iOS Distribution" found: No "iOS Distribution& ...

  5. Flink流式引擎技术分析--大纲

    Flink简介 Flink组件栈 Flink特性 流处理特性 API支持 Libraries支持 整合支持 Flink概念 Stream.Transformation.Operator Paralle ...

  6. 优化 | Redis AOF重写导致的内存问题 不错

    一.问题说明 业务上接到报警提示服务器内存爆了,登录查看发现机器剩余内存还很多,怀疑是被OOM了,查看/var/log/messages: kernel: [25918282.632003] Out ...

  7. 【ABAP系列】SAP 销售订单的行项目里条件的增强

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP 销售订单的行项目里条件的 ...

  8. js之模板方法模式

    模板方法模式的定义和组成: 模板方法模式是一种只需使用继承就可以实现的非常简单的模式. 模板方法模式由两部分结构组成,第一部分是抽象父类,第二部分是具体的实现子类.通常在抽象父类中封装了子类的算法框架 ...

  9. Python实现视频片头和片尾添加

    import imageio imageio.plugins.ffmpeg.download() from datetime import datetime import os from moviep ...

  10. (前篇:NIO系列 推荐阅读) Java NIO 底层原理

    出处: Java NIO 底层原理 目录 1.1. Java IO读写原理 1.1.1. 内核缓冲与进程缓冲区 1.1.2. java IO读写的底层流程 1.2. 四种主要的IO模型 1.3. 同步 ...