|
Basic operations, getting to know the operation Pyhon.
List
>>> Name
[ 'Zhangsan', 'lisi', 'wangwu', 'likui', 'zhangsan']
Summation
>>> Seq
[23, 34, 45, 45, 56, 56, 78, 100]
>>> Sum (seq)
437
Supplementary (Advanced usage of the list):
Heap (heaq)
Double-ended queue (deque)
String
>>> Str
'ABCDefGHijKlMnOp'
find: Find substring find returns -1
>>> Str.find ( 'DefG')
3
join: the list of elements to Mo delimiters connection
>>> '-'. Join (name)
'Tom-jonny-zhangsan-likui-wangwu'
split: string to sequence
>>> '1 + 2 + 3 + 4 + 5'.split (' + ')
[ '1', '2', '3', '4', '5']
tuple into tuple sequence
>>> Name = [ 'lisi', '46']
>>> Tuple (name)
( 'Lisi', '46')
lower: Switch to lowercase
str.lower ()
title: the first letter uppercase and the rest lowercase
str.title ()
replace: replacement string
str.replace ( 'ABC', 'DCDSA')
strip: the removal of two spaces or other strings as something n
>>> '1 + 2 + 3 + 4 + 5' .strip () '1 + 2 + 3 + 4 + 5' .strip ( " n")
'1 + 2 + 3 + 4 + 5'
>>> Max ( '23424324')
'4'
>>> Min ( '987131')
'1'
Analyzing case
Python provides isupper (), islower (), istitle () method is used to determine the case of the string. Note that:
print 'A'.isupper () #True
print 'A'.islower () #False
print 'Python Is So Good'.istitle () #True
translate (for details see Books)
dictionary:
dict: a list of key value pairs to the dictionary
d = dict (str)
clear: Clear dictionary
d.clear ()
copy: copy dictionary
y = x.copy ()
fromkeys: a list of key value pairs to the dictionary
get: get value
d.get ( 'name') <=> d [ 'name']
del certain pair of keys
del d [ 'name']
Add a couple of key
d [ 'name'] = 'zhangsan'
has_key: test whether key in the dictionary
d.has_key ( 'name')
items / iteritems: dictionary into a list
d.items ()
popitem: random key is removed
d.popitem ()
pop: Remove the key (by default the last one), and returns the value
d.pop ( 'name')
keys / iterkeys: Returns in list form key / Returns an iterator was converted list (iterkeys)
d.keys ()
values / itervalues: get a list of values worth
d.values ()
setdefault: If no key is set corresponding to a key
d.setdefault ( 'name', 'zhangsan')
update: Update Mo dictionaries keys correspond to a dictionary
d.update (x) |
|
|
|