python basis of a built-in function day16

# Data Type: int bool. . . 
# Data structure: dict list tuple set str

the reversed ()
L = [1,2,3,4,5]
l.reverse ()
Print (L)
L = [1,2,3,4,5]
L2 = the reversed (L)
Print (L2)
to retain the original list, returns a reverse iterator

L = (1,2,23,213,5612,342,43)
SLI = Slice (1,5,2)
Print (L [SLI])
Print (L [. 1:. 5: 2 ])

Print (the format ( 'Test', '<20 is'))
Print (the format ( 'Test', '> 40'))
Print (the format ( 'Test', '^ 40'))

bytes is converted into bytes type
I gbk get is encoded, I want to turn to a utf-8 encoded
print (bytes ( 'Hello', encoding = 'GBK') ) # unicode GBK is converted into bytes
print (bytes ( 'Hello', encoding = 'utf-8')) # unicode bytes utf-8 converted into the

network only transmit binary programming
photos and videos are stored in binary
html pages are crawled to encode
b_array = bytearray ( 'Hello', encoding = 'utf -8')
print(b_array)
print(b_array[0])
'\ XE4 \ XBD \ XA0 \ xe5 \ xa5 \ XBD'
S1 = 'ALEXA'
S2 = 'alexb'

L = 'ahfjskjlyhtgeoahwkvnadlnv'
L2 = L [: 10]

Slice - byte memory type does not occupy
bytes - Character string per memory

print (ord ( 'good'))
print (ord ( '. 1'))
Print (CHR (97))

Print (ASCII ( 'good'))
Print (ASCII ( '. 1'))
name = 'Egg '
Print (' Hello R & lt% '% name)
Print (the repr ('. 1 '))
Print (the repr (. 1))

Print (All ([' A ',' ', 123]))
Print (All ([' A ', 123]))
Print (All ([0,123]))

Print (the any ([' ', True, 0, []]))

L = [1,2,3,4,5]
L2 = [' A ',' B ',' C ',' D ']
L3 = (' * ',' ** ', [1,2])
D = {'k1':1,'k2':2}
for i in zip(l,l2,l3,d):
print(i)

def is_odd(x):
. 1% 2 == X return

DEF is_str (S):
return S and STR (S) .strip ()

RET = filter (is_odd, [. 1,. 6,. 7, 12 is,. 17])
RET = filter (is_str, [. 1 , 'Hello', '', '', None, [],. 6,. 7, 'World', 12 is,. 17])
Print (RET)
for I in RET:
Print (I)
[I for I in [. 1, . 4,. 6,. 7,. 9, 12 is,. 17] == 2% IF I. 1]

from Math Import sqrt
DEF FUNC (NUM):
RES = sqrt (NUM)
return RES == 0. 1%
RET = filter (FUNC, Range (1,101))
for I in RET:
Print (I)


RET = Map (ABS, [. 1, 4,6, -8])
Print (RET)
for I in RET:
Print (I)


filter after the filter is performed result set <= the number before performing
filter just filtering, does not alter the value of
the number of elements performing the same before and after the map
value may change

= L [. 1, -4,6,5, -10]
# l.sort (Key = ABS) # sort list on the basis of the original
# Print (L)

Print (the sorted (L, Key = ABS, Reverse = True )) # generates a new list without changing the original list total memory
Print (L)

L = [ '', [1,2], 'Hello World']
new_l the sorted = (L, Key = len)
Print (new_l)



Guess you like

Origin www.cnblogs.com/wang-tan/p/11082289.html