python27读书笔记0.2
# -*- coding:utf-8 -*-
##s.partition(d)
##Searches string s for the first occurrence of some delimiter string d.if s contains
##the delimiter,it returns a truple(pre,d,post),where pre is the part of s before
##the delimiter ,d is the delimiter itself,and post is the part of s after the delimiter.
##s=u'平林漠漠烟如织,寒山一带伤心碧。暝色入高楼,有人楼上愁。玉阶空伫立,宿鸟归飞急。何处是归程?长亭更短亭'
##
##print '------转换成GBK的显示方式---'
##print s.encode('GBK')
##print '-----原始编码----'
##print s
##
##li=s.partition(u',')
##
##print u'----显示元组----'
##
##print li
##
##print '----显示元组中的单个元素----'
##for i in li:
## print i.encode('GBK')
##
##s.replace(old,new[,max])
##Return a copy of s with all occurrences of string old replaced by string new.
##Normally,all occurrence are replaced;if you want to limit the number of replacements,
##pass that limit as the max argument.
##
##print 'banana'.replace('a','###')
##
##s.rfind(t[,start[,end]])
##like .find(),but if t occurs in s,this method returns the highest starting index.
##
##print 'banana'.find('a')
##print 'banana'.rfind('a')
##
##s.rindex(t[,start[,end]])
##Similar to s.index(),but it returns the last index in S where string t is found.
##It will raise a valueError exception if the string is not found.
##
##print 'banana'.index('a')
##print 'banana'.rindex('a')
##
##print 'banana'.index('c')
##
##print 'banana'.rindex('c')
##s.rjust(w[,fill])
##Return a copy of s right-justified in a field of width w,padded with spaces.
##if w<=len(s),the result is a copy of s.
##
##To pad values with some character than a space,pass that character as the optional second argument.
##print '123'.rjust(5)
##
##print '123'.rjust(5,'*')
##
##s.rpartition(d)
##Similar to s.partition(),except that it finds the last occurrence of the delimiter.
##s.rsplit(d[,max])
##Similar to s.split(d[,max]),except that if there are more fields than max,the split
##fields are taken from the end of the string instead of from the beginning.
##s.rstrip([c])
##Return s with all trailing characters from string c removed.The default value for c
##is a string containing all the whitespace characters.
##
##s.split(d[,max])
##Returns a list of strings [s1,s2,...] made by splitting s into pieces wherever the
##delimiter string d is found.The default is to split up s into pieces wherever clumps
##of one or more whitespace characters are found.
##The optional max argument limits the number of pieces removed from the front of s.
##The resulting list will have no more than max+1 elements.
##To use the max argument while splitting the string on clumps of whitespace,pass none
##as the first argumet.
##s =u'花非花,雾非雾。夜半来,天明去。来如春梦几多时。去似朝云无觅处。'
##
##for i in s.split(u'。'):
## print i.encode('GBK')
##print 'We are ready to use the max arguments'
##
##for i in s.split(u'。',2):
## print i.encode('GBK')
##s.splitlines([keepends])
##Splits s into lines and returns a list of the lines as strings.Discards the line
##sparators unless the optional keepends arguments is true.
##s=u'''江南好,
##风景旧曾谙。
##日出江花红胜火,
##春来江水绿如蓝。
##能不忆江南。'''
##
##print s.splitlines()
##for i in s.splitlines():
## print i.encode('GBK')
##s.startswith(t[,start[,end]])
##Predicate to test whether s starts with string t.Otherwise similar to .endswith().
##s.strip([c])
##Return s with all leading and trailing characters from string c removed.The default
##value for c is a string containing all the whitespace characters.
##s =u' 江南好, 风景旧曾谙。 日出江花红胜火, 春来江水绿如蓝。 '
##print s.strip()
##print s.strip(u',')
##s.swapcase()
##Return a copy of s with each lowercase character replaced by its uppercase equivalent,
##and vice versa.
##print 'abcDEV'.swapcase()
##s.upper()
##Return a copy of s with all lowercase characters replaced by their uppercase equivalents.
##s.zfill(w)
##Return a copy of s left-filled with '0' characters to width w.
## --- Type unicode: Strings of 32-bit character ---
##To get a Unicode string,prefix the string with u .
##All the operators and methods of str type are available with unicode values.
##Addititonally,for a Unicode value u,use this method to encode its value as a string of type str
##
##To encode a Unicode string U,use this method:
## U.encode('utf-8')
##
##To decode a regular str values S that contains a UTF-8 encoded value,use this method:
## S.decode('utf-8')
##>>>u16 = u'\u0456'
##>>>u16
##>>>s = u16.encode('Utf-8')
##>>>s
##
## --- Type list:Mutable sequences ---
##There are a number of functions that can be used with lists as well:
## all():Are all the elements of an iterable true?
## any():Are any of the members of an iterable true?
## cmp():Compare two values
## enumerate():Step through indices and values of an iterable
## filter():Extract qualifying elements from an iterable
## iter():Produce an iterator over a sequence
## len():Number of elements
## list():Convert to a list
## map():Apply a function to each element of an iterable
## max():Largest element of an iterable
## min():Smallest element of an iterable
## range():Generate an arithmetic progression as a list
## reduce():Sequence reduction
## reversed():Produce a reverse iterator
## sorted():Sort a sequence
## sum():Total the elements of a sequence
## xrange():Arithmetic progression generator
## zip():Combine multiple sequences
##
##
##Methods on lists
##For any list value Li,these methods are available.
##Li.append(X):Append a new element x to the end of list Li.Does not return a value.
##Li.count(x):Return the number of elements of Li that compare equal to x.
##Li.extend(s):Append another sequence s to Li
##Li.index(x[,start[,end]]):
## If Li contains any elements that equal x,return the index of the first such element,otherwise
## raise a valueError exception.
## The option start and end arguments can be used to search only positions
## with the slice Li[start:end]
##
##Li.insert(i,x):Insert a new element x into list Li just before the ith element,
##shifting all higher-number elements to the right.No value is returned.
##Li.pop([i])
##Remove and return the element with index i from Li.The default value for i is -1,
##so if you pass no argument,the last element is removed.
##Li.remove(x)
##Remove the first element of Li that is equal to x.If there are not any such elements,
##raises ValueError.
##Li.reverse(): Reverses the elements of Li in place.Does not return a result.
##Li.sort(com[,key[,reverse]]])
##Sort list Li in place.Does not return a result.
##The reordering is guaranteed to be stable--that is,if tow elements are considered equl,
##their order after sorting will not change.
## --- Types set and frozenset:set types ---
##Mathematically speaking ,a set is an unordered collection of zero or more distinct elements.
##Most operations on sets work with both set and frozenset types.
##Values of type set are mutable:you can add or delete members.
##There are two ways to create a mutable set.
##In all python version of the 2.x series,the set(S) function operates on a sequence S and returns
##a mutable set containing the unique elements of S. The arguments is optional;if omitted,
##you get a new , empty set.
##Li = [1,3,5,3,3,5,5,9,8,8,0]
##s1 = set(Li)
##s2 = set()
##s3 = set('notlob bolton')
##print Li,len(Li)
##print s1,len(s1)
##print s2,len(s2)
##print s3,len(s3)
##A frozenset value is immutable:you can not change the membership,but you can use
##a frozenset value in contexts where set values are not allowed. For example,you can
##use a frozenset as a key in a dictionary ,but you cant not use a set values
##as a dictionary key.
--- Type dict:Dictinonaries ---
Python dictionaries are one of its more powerful built-in types.They are generally
used for look-up tables and many similare applications.
A Python dictionary represents a set of zero or more ordered pairs(ki,vi) such that:
Each k value is called a key;
Each key is unique and immutable;
and the associated value vi can be of any type.
Another term for this structure is mapping ,since it maps the set of keys onto the set
of values (in the algebraic sense).
Operations on dictionaries
These operations are available on any dictionary object D:
len(D):returns the number of key-value pairs in D.
D[k]: If diactionary D has a key whose value is equal to K,this operation
returns the corresponding value for that key.If there is no matching key,
it raises a KeyError exception.
D[k] = v : If dictionary D dose not have a key-value pair whose key equals k,
a new pair is added with key k and value v.
If D already has a key-value pair whose key equals k,the value of that pair is replaced by v.
k in D : A predicate that tests whether D has a key equal to k.
k not in D: A predicate that tests whether D does not have a key equal to k.
del D[k]: In Python ,del is a statement ,not a function;If dictionary D has a
key-value pair whose key equals k,that key-value pair is deleted from D. If there
is no matching key-value pair,the statement will raise a KeyError exception.
D.get(k,x):If dictionary D has a key equal to x,it returns the corresponding value,
that is ,it is the same as the expression "D[x]".
python27读书笔记0.2的更多相关文章
- python27读书笔记0.3
#-*- coding:utf-8 -*- ##D.has_key(k): A predicate that returns True if D has a key k.##D.items(): Re ...
- python27读书笔记0.1
--Notes: 测试环境:Windows ,python 2.7.3,python 自带的IDLE #-*- coding: utf-8 -*- # First Lesson# --- Line s ...
- 驱动开发学习笔记. 0.06 嵌入式linux视频开发之预备知识
驱动开发读书笔记. 0.06 嵌入式linux视频开发之预备知识 由于毕业设计选择了嵌入式linux视频开发相关的项目,于是找了相关的资料,下面是一下预备知识 UVC : UVC,全称为:USB v ...
- 驱动开发学习笔记. 0.05 linux 2.6 platform device register 平台设备注册 2/2 共2篇
驱动开发读书笔记. 0.05 linux 2.6 platform device register 平台设备注册 2/2 共2篇 下面这段摘自 linux源码里面的文档 : 内核版本2.6.22Doc ...
- 驱动开发学习笔记. 0.04 linux 2.6 platform device register 平台设备注册 1/2 共2篇
驱动开发读书笔记. 0.04 linux 2.6 platform device register 平台设备注册 1/2 共2篇下面这段摘自 linux源码里面的文档 : Documentatio ...
- 驱动开发学习笔记. 0.02 基于EASYARM-IMX283 烧写uboot和linux系统
驱动开发读书笔记. 0.02 基于EASYARM-IMX283 怎么烧写自己裁剪的linux内核?(非所有arm9通用) 手上有一块tq2440,但是不知道什么原因,没有办法烧boot进norflas ...
- 驱动开发学习笔记. 0.01 配置arm-linux-gcc 交叉编译器
驱动开发读书笔记. 0.01 配置arm-linux-gcc 交叉编译器 什么是gcc: 就像windows上的VS 工具,用来编译代码,具体请自己搜索相关资料 怎么用PC机的gcc 和 arm-li ...
- 【英语魔法俱乐部——读书笔记】 0 序&前沿
[英语魔法俱乐部——读书笔记] 0 序&前沿 0.1 以编者自身的经历引入“不求甚解,以看完为目的”阅读方式,即所谓“泛读”.找到适合自己的文章开始“由浅入深”的阅读,在阅读过程中就会见到 ...
- 《玩转Django2.0》读书笔记-探究视图
<玩转Django2.0>读书笔记-探究视图 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 视图(View)是Django的MTV架构模式的V部分,主要负责处理用户请求 ...
随机推荐
- [面试算法题重做]求1+2+...+n
题目:求1+2+…+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字以及条件判断语句(A?B:C). 不能用条件语句,基本上只有考虑递归. 常规解法: 利用构 ...
- 信号之sigsetjmp和siglongjmp函数
在信号处理程序中经常调用longjmp函数以返回到程序的主循环中,而不是从该处理程序返回. 但是,调用longjmp有一个问题.当捕捉到一个信号时,进入信号捕捉函数,此时当前信号被自动地加到进程的信号 ...
- 信号之kill和raise函数
kill函数将信号发送给进程或进程组.raise函数则允许进程向自身发送信号. #include <signal.h> int kill(pid_t pid, int signo); in ...
- php转义和去掉html、php标签函数
/** * 转义html字符 * * @param string|array $var */function fhtmlspecialchars($var) { if (is_array ( $var ...
- Jquery的$命名冲突
在Jquery中,$是JQuery的别名,所有使用$的地方也都可以使用JQuery来替换,如$('#msg')等同于JQuery('#msg')的写法.然而,当我们引入多个js库后,在另外一个js库中 ...
- BIEE Setup
ORACLE 出品的产品绝对都可以称得上装X神器:安装文件一定要大(小水管不让你下个三天三夜那都不叫oracle),系统内存必须得大.硬盘空间必须足够多.安装时间必须足够长.各种配置必须足够复杂.学习 ...
- 【思考】由安装zabbix至排障php一系列引发的思考
[思考]由安装zabbix至排障php一系列引发的思考 linux的知识点林立众多,很有可能你在排查一个故障的时候就得用到另一门技术的知识: 由于linux本身的应用依赖的库和其它环境环环相扣,但又没 ...
- 3.x vector的用法
#include<vector> //struct struct GOLD_STRUCT { Sprite * goldspSprite; int goldValue; ...
- PHP基础2
一.函数赋值问题 function add($num1,$num2=5){ echo $num1+$num2; } add(5,19); 二.global 全局变量 把变量加入到全局变量数组中 ...
- Entity Framework 学习整理(分播客整理)
MSDN: http://msdn.microsoft.com/en-us/data/aa937723 台湾博客: http://www.dotblogs.com.tw/yc421206/ http: ...