Reading notes "python basis" __1

'' ' 
Learning pyhon basis

0xAF octal, hexadecimal 010
pow 3 power (2,3) 2
__future__ introduced into the next version of the current version of the characteristics
\ transfer
r identifies the source string

python has 6 built in sequence: a list, Unicode string string buffer ancestral target objects xrange
general sequence of operations: the index fragment sequences are added, the minimum length of the maximum multiplication membership
membership: in a checks whether the sequence
[2: 10: 1] step 1 represents long
will have a list of characters converted into a string
'' .join (somelist)

modified list, list [2] = XX
del list [2] remove
the number of count statistics appear [1,2,4,3,2, l, 4] .count (. 1)
Extend (List)
index ( 'value') in the following table to obtain
reverse reverse text
sort:
Key = len
reverse to true =
template string:
S = template ( '$ A $ Thing Never MUST Action ')
D} = {
D [' Thing '] =' Selen '
D [ 'Action'] = 'ACT'
s.substitute (D)
from Import Template String
S = tempalte ( '$ .oooo X')
s.substitute (X = 'Hello')

format string:
dictionary: len returns the number of key-value
d [k] return value
del d [k] to delete the item k
k d in k check if there is a key entry
d.get ( 'name') has no return value is returned none
d .items () into list
d.iteritems () into iterator
d.keys () returns a list key
d.update (d) updating a dictionary
d.setdefault ( 'name', N / a)
listing pushed formula :
[X * X for X in Range (10)]
[X * X for X in Range (10) == 0. 3% iF X]


Callable () function determines whether the available

documented function
Print (Help ())
'' '
storage = {}
me = 'Magnus Lie Hetland'
storage['first'] = [me]
storage['middle'] = [me]
storage['last'] = [me]


def init(data):
data['first'] = {}
data['middle'] = {}
data['last'] = {}
def lookup(data,label,name):
return data[label].get(name) #获得键的值
storage = {}
init(storage)
print(storage)


def stor(data,full_name):
names = full_name.splite() #分成列表
print(names)
if len(names) == 2 :names.insert(1,'')
labels = 'first','middle','last'
for label,name in zip(labels,names): #返回一个可迭代对象
people = lookup(data,label,name) # return label value
if people:
people.append (FULL_NAME)
the else:
Data [label] [name] = [FULL_NAME]

'' '
collection parameters:
DEF print_params (X, Y, Z =. 3, pospor *, ** keypar):
Print (X, Y, Z)
Print (pospor)
Print (keypar)
print_params (1,2,3,4,5,6, = foo. 1, bar = 2)
l, 2,3
(4,5,6)
{foo:. 1, bar : 2}
'' '

DEF the Add (X, Y): X + Y return
PAR = (1,2)
the Add (PAR *) # reverse process parameters collected

def hello_3 (greet =' hello ' , name =' world ' ):
Print ( '% S, S%'% (the greet, name))
PAR = { 'name': 'Selen', 'the greet': 'Hello'}
hello_3 (** PAR) solution # dictionary


def stor (* kwargs *):
return 'Once there WAS A'\
'%(job)s called %(name)s.'%kwargs

def power(x,y,*other):
if other:
print('recv:'.other)
else:
return pow(x,y)
def interval(start,stop=None,step=1):
if stop is None:
start, stop = 0,start
result = []
i=start
while i< stop:
result.append(i)
i+=step

return result

#作用域
x = 1
scope = vars() #返回一个不可修改字典
print(scope['x'])


def search(sequeue,number,lower = 0,upper = None):
if upper is None: upper = len(sequeue)-1
if lower == upper:
assert number == sequeue[upper]
return upper
else:
= Middle (Lower Upper +) // 2
IF Number> sequeue [ 'Middle']
return Search (sequeue, Number, Middle =. 1, Upper)
the else:
return Search (sequeue, Number, Lower, Middle-. 1

)
polymorphism Package

__metclass__ = type using the newer class
variable binding method.

Guess you like

Origin www.cnblogs.com/countryboy666/p/11484208.html
Recommended