# -*- 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的更多相关文章

  1. python27读书笔记0.3

    #-*- coding:utf-8 -*- ##D.has_key(k): A predicate that returns True if D has a key k.##D.items(): Re ...

  2. python27读书笔记0.1

    --Notes: 测试环境:Windows ,python 2.7.3,python 自带的IDLE #-*- coding: utf-8 -*- # First Lesson# --- Line s ...

  3. 驱动开发学习笔记. 0.06 嵌入式linux视频开发之预备知识

    驱动开发读书笔记. 0.06  嵌入式linux视频开发之预备知识 由于毕业设计选择了嵌入式linux视频开发相关的项目,于是找了相关的资料,下面是一下预备知识 UVC : UVC,全称为:USB v ...

  4. 驱动开发学习笔记. 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 ...

  5. 驱动开发学习笔记. 0.04 linux 2.6 platform device register 平台设备注册 1/2 共2篇

    驱动开发读书笔记. 0.04  linux 2.6 platform device register 平台设备注册  1/2 共2篇下面这段摘自 linux源码里面的文档 : Documentatio ...

  6. 驱动开发学习笔记. 0.02 基于EASYARM-IMX283 烧写uboot和linux系统

    驱动开发读书笔记. 0.02 基于EASYARM-IMX283 怎么烧写自己裁剪的linux内核?(非所有arm9通用) 手上有一块tq2440,但是不知道什么原因,没有办法烧boot进norflas ...

  7. 驱动开发学习笔记. 0.01 配置arm-linux-gcc 交叉编译器

    驱动开发读书笔记. 0.01 配置arm-linux-gcc 交叉编译器 什么是gcc: 就像windows上的VS 工具,用来编译代码,具体请自己搜索相关资料 怎么用PC机的gcc 和 arm-li ...

  8. 【英语魔法俱乐部——读书笔记】 0 序&前沿

    [英语魔法俱乐部——读书笔记] 0 序&前沿   0.1 以编者自身的经历引入“不求甚解,以看完为目的”阅读方式,即所谓“泛读”.找到适合自己的文章开始“由浅入深”的阅读,在阅读过程中就会见到 ...

  9. 《玩转Django2.0》读书笔记-探究视图

    <玩转Django2.0>读书笔记-探究视图 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 视图(View)是Django的MTV架构模式的V部分,主要负责处理用户请求 ...

随机推荐

  1. C#_StringBuilder分离字符串实例

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Stri ...

  2. 多台Linux服务器SSH相互访问无需密码--转

    一.环境配置 1.系统:CentOS release 5.6   IP:192.168.4.200   主机名:JW01 2.系统:CentOS release 5.9   IP:192.168.4. ...

  3. Cannot open URL…

    启动intellij时出现cannot open URl,原来是过滤器写错,把所有地址都拦截了..

  4. 多线程NSOperation

      NSOperation(经常使用): 1.为什么会有NSOperation?弥补gcd的一些问题:1)下载为例子:如果gcd放到队列中的block操作面对网络有问题,block之外无法取消bloc ...

  5. multithread synchronization use mutex and semaphore

    #include <malloc.h> #include <pthread.h> #include <semaphore.h> struct job { /* Li ...

  6. ppss

    parallel processing shell script Oct 19 Q: how to schedule multi-cpus on each event?

  7. 灯笼Lantern下载及使用教程

    http://www.iyaxi.com/2015-11-17/732.html 最新科学上网QQ群群号:465166189点击链接加入群[翻越长城三群]:http://jq.qq.com/?_wv= ...

  8. FPGA设计—UVM验证篇 Hello world

    这里就不赘述UVM为何物了,做了半年多的FPGA设计验证工作,按需求一直是用VHDL编写测试程序,最近看了几天UVM验证方法学的书,感觉这是一种很好的验证工具,现在开始UVM的学习,于是准备用Mode ...

  9. Hadoop基于Protocol Buffer的RPC实现代码分析-Server端

    http://yanbohappy.sinaapp.com/?p=110 最新版本的Hadoop代码中已经默认了Protocol buffer(以下简称PB,http://code.google.co ...

  10. [01] Oracle数据库简介

    Oracle关系型数据库:建立在关系模型上. Oracle10g:g(grid)网格技术,网格计算(Grid Computing)通过网络共享,将大量的计算机连接起来,联合各个计算机的多余处理能力,产 ...