I recently read from many colleaguesCode, Encountered some Python statements that have never been used before, accumulate it.
1. Obtain the local MAC address:
Import UUID
MAC = UUID. uuid1 (). HEX [-12:]
2 del usage
A = ['B', 'C', 'D']
Del a [0]
Then a = ['C', 'D']
Del a [0: 1]
Then a = ['D']
Del
Then a is undefined.
3 A = ['C', 'd]
A. Reverse ()
A = ['D', 'C']
B = ','. Join ()
B = 'd, C'
4 import random
X = random. randint (1,100)
Y = random. Choice ('abcd ')
5 A = [1, 2, 3]
B = ['A', 'B', 'C']
C = dict (ZIP (a, B ))
Then c = {1: 'A', 2: 'B', 3: 'C '}
6 A = '1-2-4-4'
B = map (INT, A. Split ('-'))
Then B = [1, 2, 4]
7 [] Use
[]. Remove (value)
[]. Pop (INDEX) = Value
[]. Count (x) = x number in the list
{} Use
{}. Pop (key) = Value
{}. Get (key) = value or {}. Get (Key, 0) set the default value
8 A = Str. Decode ('utf-8 ')
B = Str. encode ('utf-8 ')
Str. isdigit () whether it is a numerical value
Str1 = 'abc % s' % str2
9 Import string
X = string. ascii_lowercase
Then X = 'abcdefghijklmnopqrstuvwxy'
D = enumerate (X)
C = List (d)
Then c = [(0, 'A'), (1, 'B') ......]
For I, J in D:
Then I = 0, 1, 2 ,.....
J = 'A', 'B '......
10 A = test () [0]
When the length of the result returned by test () is 1, the preceding statement is equivalent
A, = test ()