Python数据类型内置函数

  - str(字符串)

  - list(列表)

  - tuple(元组)

  - dict(字典)

  - set(收集)


list(列表)的操作

  

- (append)在列表最后追加指定的元素,返回None

 # 在列表的后面追加一个元素,返回None
lst_1 = [1,2,3,4] # 实验追加是否在原内存地址或创建一个新的内存地址赋值列表
print(id(lst_1))
# 执行结果
1256965374216 lst_2 = lst_1.append(5)
print(id(lst_1))
#执行结果
1256965374216 print(lst_1)
# 执行结果
[1, 2, 3, 4, 5] print(lst_2)
# 执行结果
None

- (clear)清除指定列表中的所有内容,返回None

 # 把列表中的内容清空,返回None
lst_1 = [1,2,3,4] # 实验是否是在原内存地址清除或创建了一个新内存地址进行清除
print(id(lst_1))
# 执行结果
1256965377096 lst_2 = lst_1.clear()
print(id(lst_1))
# 执行结果
1256965377096 print(lst_1)
# 执行结果
[] print(lst_2)
# 执行结果
None

  

- (copy)复制列表中的内容,返回一个新列表

 # 复制一个新的列表,返回列表
lst_1 = [1,2,3,4]
# 实验室是否创建了一个新的内存地址进行赋值
print(id(lst_1))
# 执行结果
1256965374664 lst_2 = lst_1.copy()
print(id(lst_2))
# 执行结果
1256965377608 print(lst_1)
# 执行结果
[1, 2, 3, 4] print(lst_2)
# 执行结果
[1, 2, 3, 4]

- (count)统计列表中指定元素出现的次数,返回None

 # 统计列表中一个元素一共出现几次,返回值
lst_1 = [1,2,2,3,4,5,6]
lst_2 = lst_1.count(2) print(lst_1)
# 执行结果
[1, 2, 2, 3, 4, 5, 6] print(lst_2)
# 执行结果
2

- (extend)将列表进行合并,返回None

 # 将列表进行合并,返回None
lst_1 = [1,2,3,4,5]
lst_2 = [6,7,8,9,10]
# 合并lst_1和lst_2,在lst_1后追加lst_2
lst_3 = lst_1.extend(lst_2) print(lst_1)
# 执行结果
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] print(lst_2)
# 执行结果
[6, 7, 8, 9, 10] print(lst_3)
# 执行结果
None

- (index)指定一个值在列表中找出它的索引,返回索引的值

 # 指定列表的值找到它的索引,返回索引
lst_1 = [1,2,3,4,5,3,6]
lst_2 = lst_1.index(3)
lst_3 = lst_1.index(3,3,7) print(lst_1)
# 执行结果
[1, 2, 3, 4, 5, 3, 6] print(lst_2)
# 执行结果
2 print(lst_3)
# 执行结果
5

- (pop)指定列表中的索引的值进行删除,默认删除最后一个,返回被删除的索引的值

 # 删除列表中指定索引的值,默认是最后一个,返回删除 索引的值
lst_1 = [1,2,3,4,5,6]
lst_2 = lst_1.pop(0)
print(lst_1)
# 执行结果
[2, 3, 4, 5, 6] print(lst_2)
# 执行结果
1 lst_3 = lst_1.pop()
print(lst_1)
# 执行结果
[2, 3, 4, 5] print(lst_3)
# 执行结果
6

- (insert)指定列表中的索引进行值的插入,返回None

 # 指定列表中的索引进行值的插入,返回None
lst_1 = [1,3,4,5,6]
lst_2 = lst_1.insert(1,2) print(lst_1)
# 执行结果
[1, 2, 3, 4, 5, 6] print(lst_2)
# 执行结果
None

- (remove)删除列表中指定的值,返回None

 # 删除指定的值,返回None
lst_1 = [1,2,3,4,5]
lst_2 = lst_1.remove(3) print(lst_1)
# 执行结果
[1, 2, 4, 5] print(lst_2)
# 执行结果
None

- (reverse)将列表进行翻转,返回None

 # 将列表进行翻转,返回None
lst_1 = [1,2,3,4,5,6,7,8,9]
# 实验是否在原地址进行翻转还是创建了一块新的内存地址
print(id(lst_1))
# 执行结果
1256964466952 lst_2 = lst_1.reverse()
print(id(lst_1))
# 执行结果
1256964466952 print(lst_1)
# 执行结果
[9, 8, 7, 6, 5, 4, 3, 2, 1] print(lst_2)
# 执行结果
None

- (sort)将类别进行有顺序的排序,返回None

 # 将列表进行排序,返回None
lst_1 = [8,6,3,5,4,2,1,7]
lst_2 = lst_1.sort()
print(lst_1)
# 执行结果
[1, 2, 3, 4, 5, 6, 7, 8] print(lst_2)
# 执行结果
None lst_3 = lst_1.sort(reverse = True)
print(lst_1)
# 执行结果
[8, 7, 6, 5, 4, 3, 2, 1] print(lst_3)
# 执行结果
None

- 列表分片操作创造一个新的内存地址

 # 用列表分片创建一个新的列表
l = [0,1,2,3,4,5,6,7,8,9]
print(l)
# 执行结果
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] print(id(l))
# 执行结果
1943410856072 l_a = l
print(l_a)
# 执行结果
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] print(id(l_a))
# 执行结果
1943410856072 # 实验证明l_a直接指向的是l的地址而不是复制到新的地址去 # 利用分片使他创建新的内存区域
l_b = l[:]
print(l_b)
# 执行结果
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] print(id(l_b))
# 执行结果
1943411459912

Python数据类型的内置函数之list(列表)的更多相关文章

  1. Python数据类型的内置函数之tuple(元组),dict(字典),set(集合)

    Python数据类型内置函数 - str(字符串) - list(列表) - tuple(元组) - dict(字典) - set(收集) tuple(元组)的操作 - (count)统计元组中元素出 ...

  2. Python数据类型的内置函数之str(字符串)

    Python数据类型内置函数 - str(字符串) - list(列表) - tuple(元组) - dict(字典) - set(收集) str(字符串)的一些操作 - 字符串相连方法 # 字符串的 ...

  3. python数据类型常用内置函数之字符串

    1.strip, lstrip, rstrip x = ' jiahuifeng ' print(x.strip(' ')) print(x.lstrip(' ')) print(x.rstrip(' ...

  4. python学习交流 - 内置函数使用方法和应用举例

    内置函数 python提供了68个内置函数,在使用过程中用户不再需要定义函数来实现内置函数支持的功能.更重要的是内置函数的算法是经过python作者优化的,并且部分是使用c语言实现,通常来说使用内置函 ...

  5. 十五. Python基础(15)--内置函数-1

    十五. Python基础(15)--内置函数-1 1 ● eval(), exec(), compile() 执行字符串数据类型的python代码 检测#import os 'import' in c ...

  6. Python的常用内置函数介绍

    Python的常用内置函数介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.取绝对值(abs) #!/usr/bin/env python #_*_coding:utf-8_ ...

  7. python 常见的内置函数

    内置函数 接下来,我们就一起来看看python里的内置函数.截止到python版本3.6.2,现在python一共为我们提供了68个内置函数.它们就是python提供给你直接可以拿来使用的所有函数.这 ...

  8. python之路——内置函数和匿名函数

    阅读目录 楔子 内置函数 匿名函数 本章小结 楔子 在讲新知识之前,我们先来复习复习函数的基础知识. 问:函数怎么调用? 函数名() 如果你们这么说...那你们就对了!好了记住这个事儿别给忘记了,咱们 ...

  9. Python---基础---数据类型的内置函数

    2019-05-23 ---------------------------- 一. #数据类型的内置函数Python有哪些数据类型?Number   数值型string   字符型list     ...

随机推荐

  1. dee

    窗口居中def center(self): screen = QDesktopWidget().screenGeometry() size = self.geometry() self.move((s ...

  2. c#上课总结

    private 是完全私有的,只有当前类中的成员能访问到. protected 是受保护的,只有当前类的成员与继承该类的类才能访问.   Ctrl+k+c  多行注释Ctrl+k+u 解除注释   e ...

  3. Servlet中的编码问题

    对于response.setContentType()和response.setCharacterEncoding()的理解: 经过一些实践,对着两个方法有了一些自己的理解,有可能今后的学习中会发现自 ...

  4. 学习笔记CB006:依存句法、LTP、n元语法模型、N-最短路径分词法、由字构词分词法、图论、概率论

    依存句法分析,法国语言学家L.Tesniere1959年提出.句法,句子规则,句子成分组织规则.依存句法,成分间依赖关系.依赖,没有A,B存在错误.语义,句子含义. 依存句法强调介词.助词划分作用,语 ...

  5. python3 re模块

    一.常用正则表达式符号和语法: '.' 匹配所有字符串,除\n以外 ‘-’ 表示范围[0-9] '*' 匹配前面的子表达式零次或多次.要匹配 * 字符,请使用 \*. '+' 匹配前面的子表达式一次或 ...

  6. 公司内网接口ip城市查询分析

    require 'rubygems' require 'json' print ARGV print "fist is :",ARGV[0] logfile="#{ARG ...

  7. ningx.conf location

    server { listen ; server_name localhost; location /dirName { alias "C:/Users/VALEB/Downloads/in ...

  8. web.py模块使用

    web.py模块 import time import web urls=("/",'hello') class hello(): def GET(self): return (t ...

  9. 在CentOS 7上安装Nginx

    本教程中的步骤要求用户拥有root权限 第一步 - 添加Nginx存储库要添加CentOS 7 EPEL仓库,请打开终端并使用以下命令: sudo yum install epel-release第二 ...

  10. homework 张一刚

    #include<stdio.h> #include<unistd.h> #include<sys/types.h> #include<sys/stat.h& ...