/usr/bin/python env# -*- coding:utf-8 -*-#字符串 string ' or ' or ' ' To represent name = ' What is your name? ' >>> name.capitalize () # capitalize the first letter of the string ' What is your name? ' >>> name = "Su shi" >>> name.title () #首字母大写 ' Su shi ' >>> Name.upper () #字母大写 ' Su shi ' >>> name.lower () # Letter lowercase ' su shi ' name = ' What is your name? ' >>> name.center (+, ' * ') # String width padding, using the original string + padding character to form a new string of the specified length      ' what is your name?****** ' name = ' What is your name? ' >>> name.endswith (' s ') # Determines whether a string ends with a string true or Flasefalse>>> name.endswith ('? ') true>>> name = " s j d " >>> name.lstrip () #去掉前面空格 ' s j d ' >>> name.rstrip () # Remove the trailing space ' s j d ' >>> name.strip () #去掉前后空格 (any parameter can be written in parentheses) ' s j d ' name = ' what is Your name? ' >>> name.find (' i ') # Finds the specified string in the string and returns-    5>>> when it is not found; name.find (' SS ') -1>>> name.replace (' name ', ' SSS ') #替换特定字符 ' what is your sss? ' Split into List>>> name.split () [' What ', ' is ', ' your ', ' name? ' #分割为list (can be written in parentheses with any character split) >>> print "ssss\njjjjjjjj\tkkkkkkkkk\n \tllllllllllll "ssssjjjjjjjj kkkkkkkkk llllllllllll \t Indent \n line feed
English word:
Title:
N. champion; title; titles; rights; subtitles
Vt. Add title to; give title; called the
Adj. title;
Upper:
adj. Above, upper, High
N. (upper) names; (British) Ernie
Lower:
Vt. Weaken, reduce, lower, lower; belittle.
VI. Reduce, weaken, drop
Adj. downstream, subordinate, inferior
N. (Lower) name; (English, Italian) Mrs. Lowery
Strip:
Vt. Take away, strip, strip; strip, striptease
VI. Undress
Split
Vt. Separate, split, split, leave, break up
VI. To leave, to be split, to sever a relationship
N. split; crack
adj. split
Replace
Vt. Replace, replace, replace, To replace, return, repay, or pay for; Put it back in the same place
Capitalize
Vt. Capitalization; write in uppercase letters; estimate ... The value of
VI. Use; accumulate capital
Center
N. Center, Central; center point
Adj. Central, bit in the middle of the
Vt. Centered, so that it gathers at a point; Center
VI Center, is placed in center
N. Center) name (English) Saint
#列表 list [] to denote >>> names = [' chenglong ', ' Zhangjie ', ' wujing '] #chenglong代表本列表的元素, where he is called index >>> print names[0]chenglong>>> print names[-1] #访问素数时之返回该元素 Do not include brackets and quotes wujing>>> names[0] = ' Jiecheng ' #修改元素 >>> names[' Jiecheng ', ' Zhangjie ', ' wujing '] >>> names.append (' sushi ') #末尾添加元素 >>> names[' Jiecheng ', ' Zhangjie ', ' wujing ', ' Sushi '] >>> names.insert (0, ' fangzunming ') #在任意位置插入元素 >>> names[' fangzunming ', ' Jiecheng ', ' Zhangjie ', ' wujing ', ' Sushi ']>>> del names[3] #在任意位置删除元素 >>> names[' fangzunming ', ' Jiecheng ', ' Zhangjie ', ' wujing ', ' Zl2 ', ' sucan ', ' Sushi '] method pop () Delete element >>> poppen_name = names.pop () in parentheses can write any index >>> print poppen_namesushi>>> print names[' fangzunming ', ' Jiecheng ', ' Zhangjie ', ' wujing ', ' zl2 ', ' Sucan ']>>> name.index (' Jiecheng ') #获取元素的索引1 >>> print names[' Jiecheng ', ' Zhangjie ', ' Wujing ', ' zl2 ', ' Sucan '] #根据值删除元素 >>> names.remove (' zl2 ') >>> print names[' Jiecheng ', ' Zhangjie ', ' wujing ', ' Sucan ']
English words
Insert
Vt. Insert; embed
N. Inserting material
Append
Vt. Attach, affix, affix, stamp
N. Setting the search path for a data file
Del
N. Deleting a file; [number] inverted triangle
N. (Del) name; (Hungary) Dell; (Cambodia)
Pop
Pop
#对列表进行永久性排序 >>> names = [' B ', ' C ', ' d ', ' a '] forward >>> names.sort () >>> names[' A ', ' B ', ' C ', ' d ']> >> Names.sort (reverse=true) reverse >>> names[' d ', ' C ', ' B ', ' A ']>>> #对列表进行临时排序 >>> sorted ( names) [' A ', ' B ', ' C ', ' d '] #reverse反转列表 >>> print names[' d ', ' C ', ' B ', ' A ']>>> names.reverse () >>& Gt Print names[' A ', ' B ', ' C ', ' d '] #确定列表的长度 >>> print names[' A ', ' B ', ' C ', ' d ']>>> len (names) 4
>>> digits = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]>>> min (digits) min 0>>> max (digits) Max 9>>& Gt sum (digits) Total 45
English words
Sorted
Adj, classified, sorted, selected, or selected
V. [GAUGE] Category (sort of past participle)
Reverse
N. reverse; reverse; fail.
Vt. To reverse the reversal of;
Adj adj. Opposite, reversed, or reflexive
VI. retrogression; inverse call
Sort
N. kind; way; quality
VI. Classification, coordination, communication
Vt. Will... to classify; To pick out something in a sort of order;
Range
N. scope; range; row; mountain
VI. Parallel, as a line; extend; roam; reach
Vt. To make a parallel or a move.
N. (Range) name; (Portugal) Causingthe; (Sweden, Germany) Lange
Dictionary dict uses {} to denote >>> dict = {' name ': ' Jike ', ' age ': ' Job ': ' IT '} >>> dict [' Name '] #查看key对应的值 ' jike ' >>> dict.get (' name ') #查不到不报错 ' Jike ' >>> dict.get (' SSS ') >>> dict.has_key (' name ') #判断是否存在这个keyTrue >> > dict.has_key (' JJ ') false>>> dict.setdefault (' addr ', ' Beijing ') # No then add have the return value ' Beijing ' >>> dict{' addr ': ' Beijing ', ' job ': ' IT ', ' age ': 30, ' name ': ' jike '}>>> dict.setdefault (' age ', 30>>> dict{' addr '): ' Beijing ', ' job ': ' IT ', ' age ': 30, ' name ': ' Jike '}>>> a = {' addr ': ' Shanghai ', ' getder ': ' Nan '}>>> dict.update (a) #没有添加, there is a replacement >>> dict{' job ': ' IT ', ' getder ': ' nan ', ' addr ': ' Shanghai ', ' age ': 30, ' name ': ' jike '}>>> dict.pop (' name ') #删除key对应的值 ' Jike ' >>> dict{' job ': ' IT ', ' age ': 30}>>> dict[' name ']= ' Hukang ' #增加key对应值 >>> dict{' job ': ' IT ', ' age ': 30, ' name ': ' Hukang '}> >> dict.popitem () #随机删除key对应值 (' Job ', ' IT ') >>> dict{' age ': 30, ' name ': ' Hukang '}dict = {' name ': ' Jieke ', ' age ': ' A ', ' job ': ' IT '}for i in dict: print i,dict[i] #打印字典全部keyfor k,v in dict.items (): #打印字典全部key (smaller dictionary) to list print k,v >>> dict = {' name ': ' Jike ', ' age ': ' Job ': ' IT '}>>> dict2 = dict #起一个别名 >>> dict2{' job ': ' IT ', ' age ': 30, ' namE ': ' jike>>> dict3 = dict.copy () #浅copy >>> dict3{' job ': ' IT ', ' age ': 30, ' name ': ' Jike '}>>> dict4 = Copy.deepcopy (dict) #深copy (full copy) >>> dict{' job ': ' IT ', ' age ': 30, ' name ': ' Jike '}
collection Features: go to heavy , Relationship test >>> name = {1,2,3,4} >>> type (name) <type ' Set ' >>>> names = {3,4,5,6}>>> name,names (Set ([1, 2, 3, 4]), set ([3, 4, 5, 6])) >>> name & names #交集set ([3, 4]) >>> names | name #合集set ([1, 2, 3, 4, 5, 6]) >>> name - names #差级 Set ([1, 2])
For __ in __: Loop list
If __[< > =! =] __: Judging, contrasting
While true: True
A = Inpput user input
English words
Break
VI. Break down;
Vt. To break (make) (a record) or (usually a good weather) to change; start
VI. (voice) mutation; break out; sudden fall of (price)
N. Rupture, interruption, change (a condition that lasts for a period of time), intermittent
Continue
VI. Continuation, continuation, continuous
Vt. Continue to say ... N. to make a. To make a move; Extend
This article is from "Dream Chaser" blog, please make sure to keep this source http://dreamchaser.blog.51cto.com/7756851/1962574
Python Common data types