栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python

目录

一、list和tuple的区别

二、学到的序列有哪几种

三、list中所有方法的使用

1. append(self, object, /)   给列表追加一个元素

2. clear(self, /)  清除列表元素

3. copy(self, /)

4.count(self, value, /)    计数

5.extend(self, iterable, /)   添加

6.index(self, value, start=0, stop=9223372036854775807, /)  查找

7.insert(self, index, object, /)    插入(下标,插入的元素)

8.pop(self, index=-1, /)  弹出

9.remove(self, value, /)  删除第一个值

10.reverse(self, /)   倒置

11.sort(self, /, *, key=None, reverse=False)      排序

四、将元组和列表转换成字典

       1.将元组转换为字典

       2.将列表转换为字典

五、dict中所有方法的使用

1.clear(...)

2.copy(...)

3.get(self, key, default=None, /)      返回key的值

4.items(...)   用于返回字典中所有的键值对(key-value)

5.keys(...)     用于返回字典中的所有键(key)

6.pop(...)     用来删除指定的键值对

7.popitem(self, /)        用来删除最后一个键值对

8.setdefault(self, key, default=None, /)   用来返回某个 key 对应的 value

9.update(...)   将后一个字典中的元素添加到前一个字典的首部

10.values(...)   用于返回字典中所有键对应的值

六、list或dict浅拷贝画图加代码解释

1.dict浅拷贝

2.list浅拷贝


一、list和tuple的区别

       List是可变数据类型,tuple是不可变数据类型;

二、学到的序列有哪几种

       str、bytes、tuple、list

三、list中所有方法的使用

1. append(self, object, /)   给列表追加一个元素

      Append object to the end of the list.

2. clear(self, /)  清除列表元素

      Remove all items from list.

3. copy(self, /)

      Return a shallow copy of the list.

4.count(self, value, /)    计数

       Return number of occurrences of value.

5.extend(self, iterable, /)   添加

       Extend list by appending elements from the iterable.

6.index(self, value, start=0, stop=9223372036854775807, /)  查找

        Return first index of value.

Raises ValueError if the value is not present.

7.insert(self, index, object, /)    插入(下标,插入的元素)

       Insert object before index.

8.pop(self, index=-1, /)  弹出

       Remove and return item at index (default last).

       Raises IndexError if list is empty or index is out of range.

9.remove(self, value, /)  删除第一个值

       Remove first occurrence of value.

       Raises ValueError if the value is not present.

10.reverse(self, /)   倒置

       Reverse *IN PLACE*.

11.sort(self, /, *, key=None, reverse=False)      排序

Sort the list in ascending order and return None.

四、将元组和列表转换成字典

       1.将元组转换为字典

       2.将列表转换为字典

五、dict中所有方法的使用

1.clear(...)

      D.clear() -> None.  Remove all items from D.

2.copy(...)

     D.copy() -> a shallow copy of D

3.get(self, key, default=None, /)      返回key的值

       Return the value for key if key is in the dictionary, else default.

4.items(...)   用于返回字典中所有的键值对(key-value)

       D.items() -> a set-like object providing a view on D's items

5.keys(...)     用于返回字典中的所有键(key)

       D.keys() -> a set-like object providing a view on D's keys

6.pop(...)     用来删除指定的键值对

       D.pop(k[,d]) -> v, remove specified key and return the corresponding value.

       

       If key is not found, default is returned if given, otherwise KeyError is raised

7.popitem(self, /)        用来删除最后一个键值对

       Remove and return a (key, value) pair as a 2-tuple.

      

       Pairs are returned in LIFO (last-in, first-out) order.

       Raises KeyError if the dict is empty.

8.setdefault(self, key, default=None, /)   用来返回某个 key 对应的 value

       Insert key with a value of default if key is not in the dictionary.

      

       Return the value for key if key is in the dictionary, else default.

9.update(...)   将后一个字典中的元素添加到前一个字典的首部

       D.update([E, ]**F) -> None.  Update D from dict/iterable E and F.

       If E is present and has a .keys() method, then does:  for k in E: D[k] = E[k]

       If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v

       In either case, this is followed by: for k in F:  D[k] = F[k]

10.values(...)   用于返回字典中所有键对应的值

       D.values() -> an object providing a view on D's values

六、list或dict浅拷贝画图加代码解释

1.dict浅拷贝

2.list浅拷贝

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/969451.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号