笨办法:
a = ['Admin', '127.0.0.1', '8080', 'maya_matthew_guaranty']
name = a[0]
server = a[1]
port = a[2]
password = a[3]
Pythonic:
a = ['Admin', '127.0.0.1', '8080', 'maya_matthew_guaranty']
name , server, port , password = a
Test on MacBook Air (11-inch, Early 2015) 1.6 GHz Intel Core i5
List: List Time used: 7.607762999999999
import time
start = time.clock()
a = range(10000000)
b = range(10000000)
c = []
for i in range(len(a)):
c.append(a[i] + b[i])
elapsed = (time.clock() - start)
print("List Time used:",elapsed)
Numpy: Time used: 0.259793
import time
start = time.clock()
import numpy as np
a = np.arange(10000000)
b = np.arange(10000000)
c = a + b
elapsed = (time.clock() - start)
print("Time used:",elapsed)
# 当需要传递的参数很多时,打包成字典 | |
myDict = { | |
'one': 1, | |
'two': 2, | |
'three': 3} | |
a, b, c = myDict.values() | |