面接の本題説明
21620 ワード
、 (32 )
1、python A
A、char # , c , python
B、int
C、float
D、list
2. E
x = “foo”
y = 2
print(x+y)
A.foo B.foofoo C.foo2 D.2 E.An exception is thrown
3、 B
A、 1
B、 \0 # C
C、 ,
D、
4、 C
A、dic1 = {}
B、dic2 = {123:345}
C、dic3 = {[1,2,3]:'uestc'} # key : ,
D、dic3 = {(1,2,3):'uestc'}
5.Kvps = {‘1’:1,’2’:2} D
theCopy = kvps
kvps[‘1’] = 5
sum = kvps[‘1’] + theCopy[‘1’]
Print sum
A.1 B.2 C.7 D.10
6、 : B
A.x in range(6) # 1 in range (4)
B.3=a # , 3 = a
C.e>5 and 4==f D(x-6)>5
7、 True B
A.5+4j>2-3j B.3>2==2
C. e>5 and 4==f D.(x-6)>5
8、 x=43,ch=‘A’,y = 1, (x>=y and ch
ascll a 65 100
A、0
B、1 True and 1 --> 1
C、
D、True
9、 True : c
A、3>2>2
B、’abc’>’xyz’
C、0x56 > 56 0x56 16
D、(3,2)>(‘a’,’b’) # int str ()
10、 Python ( ) AD
A、min = x if x < y else y
B、max = x > y ? x : y # c
C、if(x>y) print(x)
D、while True:pass
11. k , while : A
k=1000
while k>1:
print k # python 2
k=k/2
A.9 # py2 B.10 # py 3
C.11 D.100
12、 : B
A、continue #
B、 break
C、 break continue
D、 , goto # goto c ,python
13、 python , B
A、 real+image j
B、
C、 j j
D、 conjugate # 2+3j 2-3j
14、 : B
A、for a in range(10): # for
time.sleep(10)
B、while 1<10:
time.sleep(10)
C、while True:
break
D、a = [3,-1,',']
for i in a[:]:
if not a:
break
15、 , 1,2,3 ( , ): BD
A 、for i in range(3):
print(i)
B、aList = [0,1,2]
for i in aList: # 0,1,2
print(i+1) # 1,2,3,
C、i = 1
while i < 3:
print(i)
i+=1
D、for i in range(3):
print(i+1)
16、Python : C
A、class ( arg1, arg2,… argN)
B、function (arg1,arg2,…argN)
C、def (arg1,arg2,…argN) python
D、def ( arg1, arg2,… argN) # type
、 (10 )
1、 k, :
def fun()
___globals k___
k = k+1
2、L=range(100) # range
1) _____L[0:3] ----> list(L[:3])# list
2) _______L[-2]
3) _______L[-10:] ---> list([-10:])
4) L L1 _______L1 = L.copy()
L1 =L ( )
3、 dict key _______key in dict
get()
4、 list , ____len(list)__ ____list.append()___
5. : _______
def extendList(val,list=[]):
list.append(val)
return list
list1 = extendList(10)
list2 = extendList(123,[]) # list
list3 = extendList('a')
print 'list1 = %s'%list1 [10,'a']
print 'list2 = %s'%list2 [123]
print 'list3 = %s'%list3 [10,'a']
6. :___yes____
x=True
y=False
z=False
if x or y and x:
print "yes"
else:
print "no"
、 (20 )
1、
,
type(a)is str
2、is ==
is
==
3、Python tuple list 。
tuple() list()
4、list tuple
list tuple
5、 list 。
set() difference() , intersection()
or s&b a-b
set1 = {1,2,3,4,5}
set2 = {4,5,6,7,8}
print(set1 & set2) # {4, 5}
print(set1.intersection(set2)) # {4, 5}
set1 = {1,2,3,4,5}
set2 = {4,5,6,7,8}
print(set1 - set2) # {1,2,3}
print{set1.difference(set2)} # {1,2,3}
6、Python ?
*args,key=1,**kwargs( )
7、*args **kwargs ? **kwargs
,*args ,**kwargs
def timer(func):
def inner(*args,**kwargs):
print(' ')
ret = func(*args,**kwargs)
print(' ')
return ret
return inner
@timer
def li2():
print(' ')
li2()
8、 unicode,utf-8,gbk ?
unicode , ==
utf-8 == 2
gbk ==2
gbk utf-8 unicode
9、 python
import os
os remove(‘ ’)
10、def func(a,b,c=0,*args,**kwargs): # c=0 *args
pass
*args,**kwargs ?
*args ,**kwargs
、 (38 )
1、d={‘a’:1,’b’:2,’c’:3} key、value (3 )
d={'a':1,'b':2,'c':3}
for k in d:
print(k,d[k])
# 2、 Python list 。(6 )#
li = [1,2,2,2,2,3,4,55,55]
set1 = set(li)
li = list(set1)
print(li)
new_l= []
for i in li:
if i not in new_l:
new_l.append(i)
print new_l
3、 Python/C (13 )
1)
1,2,3,5,8,13,21..... , 400 ,
。
count = 2
a,b = 1,2
while a+b < 4000000:
c = a+b
a = b
b = c
count += 1
print(c) #3524578
print(count) # 32
2)
dicta = {"a":1,"b":2,"c":3,"d":4,"f":"hello"}
dictb = {"b":3,"d":5,"e":7,"m":9,"k":"world"}
, , key , key
, , :
dictc = {"a":1,"b":5,"c":3,"d":9,"e":7,"m":9,"f":"hello","k":"world"}
dicta = {"a":1,"b":2,"c":3,"d":4,"f":"hello"}
dictb = {"b":3,"d":5,"e":7,"m":9,"k":"world"}
dictc = dicta
for key in dictb:
if key in dictc:
dictc[key] = dictc[key] + dictb[key] # [key]
else:
dictc[key] = dictb[key]
print(dictc)
5、 ? , (8 )
: ,
import time
def timer(func):
def inner(*args,**kwargs):
start = time.time()
ret = func(*args,**kwargs)
end = time.time()
print(' ')
print(end-start)
return ret
return inner
@timer
def list():
print(' ')
list()
6、 log ( )(8 )
@log
def now():
print ‘2017-08-31’
>>>now()
:
def log(func):
def inner(*args, **kwargs):
print('call %s()' % func.__name__)
ret = func(*args, **kwargs)
return ret
return inner
@log
def now():
print('2017-08-31')now()
(20 )
,
。 , 。(10 )
data:{"time":"2016-08-05 T13:13:05",
"some_id": "ID1234",
"grp1":{ "fld1":1,
"fld2":2},
"xxx2":{ "fld3":0,
"fld5":0.4},
"fld6":11,
"fld7":7,
"fld46":8}
fields: "|" "fld" , :fld2|fld3|fld7|fld19 splir
def select(data,fields):
# TODO:implementation
return result
def select(data,fields):
fields_lst = fields.split(‘|’)
for key in data:
if type(data[key]) == dict:
pass
return result
data={"time":"2016-08-05T13:13:05",
"some_id":"ID1234",
"grp1":{ "fld1":1,"fld2":2},
"xxx2":{ "fld3":0,"fld5":0.4},
"fld6":{"key":{ "fld19":1}},
"fld7":7,
"fld46":8}
fields='fld2|fld3|fld7|fld19'
# : ,Alex
def select(data,fields):
l = [data]
field_lst = fields.split('|')
result = {}
while l: # l = []
data = l.pop() #data = { "fld1":1,"fld2":2}
for key in data:
if type(data[key]) == dict:
l.append(data[key]) # l = [{ "fld1":1,"fld2":2},{ "fld3":0,"fld5":0.4},{"key":{ "fld19":1}}]
elif key in field_lst:
result[key] = data[key]
return result
print(select(data,fields))
転載先:https://www.cnblogs.com/jassin-du/p/7799730.html