Python Learning: 03
An inch is worth a pound of gold, an inch of gold is hard to buy an inch of time.
- Slice
When the scale of data is so large that we have to pick a short of the content, the best way is to use Slice.
- Forward Slice
>>>L=range(1,101)
>>>L[1:] #until the end
>>>L[:101] #from the first
>>>L[1:100]
>>>L[1:101:2] #pick one in two
- Reverse Slice
>>>L=range(1,101)
>>>L[-1:]
>>>L[:-1]
>>>L[-5:-1]
>>>L[-46::5]
- Iteration
In Python, Iterations are done with "for ... in ...". 'For' loop in python can be used not only on Lists and Tuples, but alse on any other iterable objects. Therefore, the iterative operation is for a collection, whether the collection is ordered or unordered, we can always use the loop to extract each element of the collection in turn. The collection is a data structure containing a set of elements, and we have learnt List, Tuple, Set, Dict, Str, Unicode.
- Index Iteration: Using enumerate() to get the Tuple of index and name and using zip() to conbine two lists into one
for index, name in enumerate(L):
print index, '-', name
>>> zip([10, 20, 30], ['A', 'B', 'C'])
[(10, 'A'), (20, 'B'), (30, 'C')]
- The value of dict: values() and itervalues()
- The key-value of dict: items() and iteritems()
Python Learning: 03的更多相关文章
- python learning Exception & Debug.py
''' 在程序运行的过程中,如果发生了错误,可以事先约定返回一个错误代码,这样,就可以知道是否有错,以及出错的原因.在操作系统提供的调用中,返回错误码非常常见.比如打开文件的函数open(),成功时返 ...
- python进阶03 继承
python进阶03 继承 一.继承 课堂练习:假设你正在参与一个魔幻类角色游戏的开发,公司需要腻味这个游戏设计两个角色的类: a.剑士 属性:1.角色名:2.角色等级:3.生命值:4.攻击力 行为: ...
- Python模块03/re模块
Python模块03/re模块 内容大纲 re模块(正则表达式) 1.re模块(正则表达式) import re s = "meet_宝元_meet" print(re.finda ...
- Python函数03/函数名的第一类对象及使用/f 格式化/迭代器/递归
Python函数03/函数名的第一类对象及使用/f 格式化/迭代器/递归 目录 Python函数03/函数名的第一类对象及使用/f 格式化/迭代器/递归 内容纲要 1.函数名的第一类对象及使用 2.f ...
- Python面向对象03 /继承
Python面向对象03 /继承 目录 Python面向对象03 /继承 1. 初识继承 2. 单继承 3. 多继承 4. 总结 1. 初识继承 概念:专业角度:如果B类继承A类,B类就称为子类,派生 ...
- Python Learning Paths
Python Learning Paths Python Expert Python in Action Syntax Python objects Scalar types Operators St ...
- (python函数03)zip()函数
(python函数03)zip()函数 zip是用来压缩的,它接受一系列可迭代的对象作为参数,将对象中对应的元素打包成一个个元组(tuple),然后返回有这些tuples组成的对象,可强制转化为列表和 ...
- Python Learning
这是自己之前整理的学习Python的资料,分享出来,希望能给别人一点帮助. Learning Plan Python是什么?- 对Python有基本的认识 版本区别 下载 安装 IDE 文件构造 Py ...
- 我的Python笔记03
摘要: 声明:本文整理借鉴金角大王的Python之路,Day3 - Python基础3,仅供本人学习使用!!! 本节内容 1. 函数基本语法及特性 2. 参数与局部变量 3. 返回值 嵌套函数 4 ...
随机推荐
- 去除inline-block元素间的间距
一.现象描述 真正意义上的inline-block水平呈现的元素间,换行显示或者空格隔开的情况下会有间距,这是因为浏览器在解析时,会将换行等读取成一个空格导致. 二.移出空格的方法 ① 我们可以去掉元 ...
- openlayers4 入门开发系列之地图导航控件篇(附源码下载)
前言 openlayers4 官网的 api 文档介绍地址 openlayers4 api,里面详细的介绍 openlayers4 各个类的介绍,还有就是在线例子:openlayers4 官网在线例子 ...
- Android之PhotoView使用
文章大纲 一.什么是PhotoView二.代码实战三.项目源码下载 一.什么是PhotoView 一款 ImageView 展示框架,支持缩放,响应手势,位于图片排行榜的第五位,PhotoView ...
- 【Matlab&Mathematica】对三维空间上的点进行椭圆拟合
问题是这样:比如有一个地心惯性系的轨道,然后从轨道上取了几个点,问能不能根据这几个点把轨道还原了? 当然,如果知道轨道这几个点的速度的情况下,根据轨道六根数也是能计算轨道的,不过真近点角是随时间变动的 ...
- grep 及正则表达式
grpe 及正则表达式 文本查找的需要:grep,egrep,fgrepgrep: 根据模式,搜索文本,并将符合模式的文本行显示出来.Pattern : 文本字符以及正则表达式的元字符组合而成的匹配条 ...
- 如何开发使用自定义文件的OEM应用程序
有关创建和使用自定义数据文件的详细信息,请参阅DISM应用程序包(.appx或.appxbundle)服务命令行选项. 了解如何开发使用自定义文件的应用程序,将信息从OEM传递到应用程序. 对于您为O ...
- cxf 整合 spring 时 java.lang.VerifyError异常
异常信息主要有两个,Falling off the end of the code 和 illegal instruction found at offset 1: java.lang.VerifyE ...
- vue的基本指令
1.创建vue对象 <script src="vue.js"></script> var vm = new Vue({ el:"#ap ...
- 网络协议 12 - HTTP 协议:常用而不简单
系列文章传送门: 网络协议 1 - 概述 网络协议 2 - IP 是怎么来,又是怎么没的? 网络协议 3 - 从物理层到 MAC 层 网络协议 4 - 交换机与 VLAN:办公室太复杂,我要回学校 网 ...
- vue的父子组件间的相互传参props及props数据的多种验证机制
感觉自己即将完全步入前端大军,后台老板都不需要我弄了,塞翁失马...时间会告诉我们是好是坏 好了言归正传,最近vue是搞的不亦乐乎啊,下面来总结一下vue组件间的各种使用方法以及一些技巧 ------ ...