Python列表知识补充
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'] >>>
Python列表知识补充的更多相关文章
- python列表解析补充:
python列表解析补充: # 补充: f = [x + y for x in 'ABCDE' for y in '1234567'] print(f) test = [] for x in 'ABC ...
- 万恶之源 - Python基础知识补充
编码转换 编码回顾: 1. ASCII : 最早的编码. ⾥⾯有英⽂⼤写字⺟, ⼩写字⺟, 数字, ⼀些特殊字符. 没有中⽂, 8个01代码, 8个bit, 1个byte 2. GBK: 中⽂国标码, ...
- Python基础知识补充(重要)-作用域、特殊语法
Python作用域 python代码内部块如if语句内声明变量,在if代码段后在调用此变量并未报如“undefinded name"此类错误,例子如下: if 1 == 1: name = ...
- python基础知识补充
set 集合 {} 无序 集合天然去重 增 : s.add s.update 迭代添加 删 : s.pop( ) 随机删除 返回删除值 s.clear( ) 清空 获取到的是 set( ) del s ...
- 从零开始的Python学习 知识补充sorted
sorted()方法 sorted()可用于任何一个可迭代对象. 原型为sorted(iterable, cmp=None, key=None, reverse=False) iterable:一个可 ...
- python爬虫主要就是五个模块:爬虫启动入口模块,URL管理器存放已经爬虫的URL和待爬虫URL列表,html下载器,html解析器,html输出器 同时可以掌握到urllib2的使用、bs4(BeautifulSoup)页面解析器、re正则表达式、urlparse、python基础知识回顾(set集合操作)等相关内容。
本次python爬虫百步百科,里面详细分析了爬虫的步骤,对每一步代码都有详细的注释说明,可通过本案例掌握python爬虫的特点: 1.爬虫调度入口(crawler_main.py) # coding: ...
- Python学习---django知识补充之CBV
Django知识补充之CBV Django: url --> def函数 FBV[function based view] 用函数和URL进行匹配 url --> ...
- python基础知识-04-字符串列表元组
python其他知识目录 内存,cpu,硬盘,解释器 实时翻译 编译器 :一次性翻译python2,3 除法,2不能得小数,3能得小数 1.字符串操作 1.1字符串操作startswith start ...
- python基础知识(七)---数据类型补充、"雷区"、编码
数据类型补充."雷区".编码 1.数据类型补充 str: #字符串数据类型补充 s1=str(123) #常用于类型转换 print(s1) #capitalize()首字母大写 ...
随机推荐
- binlog之一:binary log初探
MySQL Binary Log也就是常说的bin-log,是mysql执行改动产生的二进制日志文件,其主要作用有两个: Replication(主从数据库):在master端开启binary log ...
- 四川第七届 C Censor (字符串哈希)
Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text pp. Her j ...
- Struts2中web.xml里面struts-cleanup作用
struts2.1.3之后的版本均不需要配置该过滤器 参考: struts-cleanup作用 升级到struts-2.3.14.3之后涉及的改动以及ActionContextCleanUp,Stru ...
- 函数指针的应用学习Demo
学习函数指针的应用 ,简单demo #include "stdafx.h" #include "SubClass.h"; //函数指针 typedef int ...
- hibernate 事务的隔离级别
脏读不可重复读幻读可序列化(符合事务的四个特性的正常情况 ) 解释: 脏读:事务A对数据1做了更新,但是还没有来得及提交 此时事务B对数据1进行了查询获得了事务A更新后的数据, 但是事务A因为一些原因 ...
- java 多线程系列基础篇(十)之线程优先级和守护线程
1. 线程优先级的介绍 java 中的线程优先级的范围是1-10,默认的优先级是5.“高优先级线程”会优先于“低优先级线程”执行. java 中有两种线程:用户线程和守护线程.可以通过isDaemon ...
- 北京儿研所自制药一览表,宝妈们必读!<转>
原帖地址:http://www.360doc.com/content/15/0910/22/22655489_498339090.shtml
- 【271】IDL-ENVI二次开发
参考:String Processing Routines —— 字符串处理函数 01 STRING 返回字符串. 02 STRCMP 比较字符串,一样返回1,不一样返回0,默认大小写敏感. ...
- Android按钮单击事件的四种常用写法
这篇文章主要介绍了Android按钮单击事件的四种常用写法总结,比较了常见的四种写法的优劣,有不错的参考借鉴价值,需要的朋友可以参考下 很多学习Android程序设计的人都会发现每个人对代码的写法都有 ...
- jquery.pagination.js使用
直接上代码: <script type="text/javascript"> var pageIndex = 1; //页面索引初始值 var pageSize = 1 ...