Python列表知识补充
时间:2022-04-22
本文章向大家介绍Python列表知识补充,主要内容包括1、import this Python之禅,圣经。、2、title() 使字符串第一个字母大写、3、列表的负索引、4、range、5、min(列表) 取最小值 max(列表) 取最大值 sum(列表) 求和、6.用切片打印整个列表、7、append 在列表末尾添加元素 insert(索引,内容)在第几个索引位置添加元素、基本概念、基础应用、原理机制和需要注意的事项等,并结合实例形式分析了其使用技巧,希望通过本文能帮助到大家理解应用这部分内容。
1、import this Python之禅,圣经。
>>> import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
2、title() 使字符串第一个字母大写
>>> s = "cairui"
>>> print(s.title())
Cairui
3、列表的负索引
-1代表最后一个元素,-2代表倒数第二元素
>>> s = ['cairui',123,456,789,'lei']
>>> print(s[-1])
lei
>>> print(s[-2])
789
>>>
4、range
>>> range(1,5)
[1, 2, 3, 4]
>>> numbers = list(range(1,5))
>>> print(numbers)
[1, 2, 3, 4]
>>>
>>> i1 = list(range(2,11,2))
>>> print i1
[2, 4, 6, 8, 10]
5、min(列表) 取最小值 max(列表) 取最大值 sum(列表) 求和
6.用切片打印整个列表
>>> players = [1,2,3,4,5]
>>> print(players[:])
[1, 2, 3, 4, 5]
>>>
7、append 在列表末尾添加元素 insert(索引,内容)在第几个索引位置添加元素
>>> s = ['a',123,456,789]
>>> s.append('rui')
>>> print(s)
['a', 123, 456, 789, 'rui']
['a', 123, 456, 789, 'rui'] >>> s.insert(0,'rui') >>> print(s) ['rui', 'a', 123, 456, 789, 'rui'] >>>
- Andrew Ng机器学习课程笔记--week10(优化梯度下降)
- Andrew Ng机器学习课程笔记--week9(下)(推荐系统&协同过滤)
- Andrew Ng机器学习课程笔记--week9(上)(异常检测&推荐系统)
- python程序员开发必备的5大工具,你用过几个?
- Andrew Ng机器学习课程笔记--week8(K-means&PCA)
- Andrew Ng机器学习课程笔记--week7(SVM)
- Pytorch windows10安装教程
- Udacity并行计算课程笔记-The GPU Programming Model
- DeepLearning.ai学习笔记(二)改善深层神经网络:超参数调试、正则化以及优化--Week2优化算法
- DeepLearning.ai学习笔记(二)改善深层神经网络:超参数调试、正则化以及优化--Week1深度学习的实用层面
- 通俗理解决策树中的熵&条件熵&信息增益
- KNN实现手写数字识别
- softmax分类算法原理(用python实现)
- DeepLearning.ai学习笔记(一)神经网络和深度学习--Week4深层神经网络
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- CMake学习笔记
- 性能分析(2)- 应用程序 CPU 使用率过高案例
- 性能测试必备知识(7)- 深入理解“CPU 使用率”
- Jmeter 常用函数(31)- 详解 __iterationNum
- Jmeter 常用函数(30)- 详解 __if
- Jmeter 常用函数(29)- 详解 __eval
- Jmeter 常用函数(28)- 详解 __FileToString
- Jmeter 常用函数(26)- 详解 __chooseRandom
- Jmeter 常用函数(25)- 详解 __V
- Java8新特性
- 线程池基础
- 多线程基础
- 02 Spring Boot整合JDBC
- 01 Spring Boot 入门
- Spring——单例Bean中使用多例Bean