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. mysql 创建用户、设置权限

    MySQL创建用户与授权 一. 创建用户 命令: CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 说明: username:你将创建的用 ...

  2. 开发Canvas 绘画应用(三):实现对照绘画

    需求分析 在我的毕设中,提出了视图引导的概念,由两部分功能组成: (1)可以对照着图片进行绘画,即将图片以半透明的方式呈现在绘图板上,然后用户可以对照着进行绘画: (2)可以直接将简笔画图片直接拖拽到 ...

  3. jmeter 上传附件脚本报Non HTTP response code: java.io.FileNotFoundException

    如果上传附件报如下错误,就需要把附件放到和脚本同一路径下就解决了

  4. java数据类型运算符类型转换

    Java基本数据类型 基本类型,或者叫做内置类型,是JAVA中不同于类的特殊类型.它们是我们编程中使用最频繁的类型,因此面试题中也总少不了它们的身影,在这篇文章中我们将从面试中常考的几个方面来回顾一下 ...

  5. tornado上帝视角第一次建立WEB服务器

    import tornado.ioloop import tornado.web 该视角建立在SOCKET服务端和客户端的基础上. class MainHandler(tornado.web.Requ ...

  6. 4. Traffic monitoring tools (流量监控工具 10个)

    4. Traffic monitoring tools (流量监控工具 10个)EttercapNtop SolarWinds已经创建并销售了针对系统管理员的数十种专用工具. 安全相关工具包括许多网络 ...

  7. CodeForce Educational round Div2 C - Vasya and Robot

    http://codeforces.com/contest/1073/problem/C   题意:给你长度为n的字符串,每个字符为L, R, U, D.给你终点位置(x, y).你每次出发的起点为( ...

  8. Lunar Lander 月球冒险

    发售年份 1979 平台 街机 开发商 雅达利(Atari) 类型 飞行模拟 https://www.youtube.com/watch?v=McAhSoAEbhM

  9. Python argparse用法

    import argparse import sys parser = argparse.ArgumentParser(description='this is for test.') parser. ...

  10. SQL语句整理