Function test

Function exercises 

one choice:
1.python unsupported data types (A)
A.char
B.int
C.float
D.list

2.x = 'foo' (E)
Y = 2
Print (X + Y )
A.foo
B.foofoo
C.foo2
D.2
E.An Exception thrown iS

3. the following statement is wrong on the string is (B)
A. characters should be treated as a string of length 1
B. string \ end flag string 0
C. either in single quotes, double quotes may be used to create a string
D. wrap carriage may comprise three special characters quoted string

4. the following statement can not create a dictionary is (C )
A.dic1 = {}
B.dic2 = {123: 345}
C.dic3 = {[l, 2,3]: 'UESTC'}
D.dic3 = {(l, 2,3): 'UESTC'}

= {5.Kvps '. 1':. 1, '2': 2} (D)
theCopy = kvps
kvps [ '. 1'] =. 5
kvps = SUM [ '. 1'] + theCopy [ '. 1']
the Print SUM
A.1
B.2
C.7
D.10

6. The Which of the following is not valid Boolean expression: (B)
A. X in Range ( . 6)
B. a =. 3
C. E> F ==. 4. 5 and
D. (X -. 6)>. 5

is True is (B) 7. following expression
A. +. 5. 4J> 2 - 3j
B .. 3> 2 # 2. 3 ==> 2 and 2 == 2
C. E> F ==. 4. 5 and
D. (X -. 6)>. 5

8. The known x = 43, ch = 'A ', y = 1, the expression (x> = y and ch < 'b' and y) is the value of (B)
A.0
B.1
C. error
D.True

9. the following expression is True is returned: (C)
A.3> 2> 2
B.'abc '>' XYZ '
C.0x56> 56 is
D. (3,2-)> (' A ','B ')

10. The following statement is correct Python (multiple choice) (A, D)
IF X = X A.min <Y Y the else
B.max X => Y X:? Y
C.if (X> Y) Print (X)
D.while True: Pass

11. The If k is an integer, while the following the number of cycles performed is: (a)
K = 1000
the while K>. 1:
Print K
K = K / 2
A.9
B.10
C.11
D.100

12. the following description is correct: (B)
A.continue end statement is used to perform the entire cycle of
B. only in the loop body break statement
using the same continue statement or break statement in the circulation in vivo effects of C.
D. exit from the multilayer loop nesting, only the goto statement

13. With regard to Python in the plural, the following statement is wrong: (no solution, four options are right)
A. indicates that the syntax is complex + Image J real
B. real and imaginary parts are floating point
C. suffix j the imaginary unit must not case sensitive and j
D. method returns the complex conjugate complex conjugate

14. the following statement will be infinite loop which: (B)
A.for in Range a (10):
the time.sleep (10)
B.while. 1 <10:
the time.sleep (10)
C.while True:
BREAK
Da = [. 3, -1, ',']
for I in A [:]:
IF Not A:
BREAK

15. the following code, which outputs three digital 1,2,3 (multiple choice, wrong no points) (B, D)
A.for I in Range (. 3):
Print (I)
B.aList = [ 0,1,2]
for I in of aList:
Print (I +. 1)
Ci of. 1 =
the while I <. 3:
Print (I)
I + =. 1
D.for I in Range (. 3):
Print (I +. 1)

16 how to define a function .Python: (C)
that A.class <name> (<type> arg1, <type> arg2, ...... <type> argN)
B.funcion <name> (arg1, arg2, ...... argN)
C.def <name> (arg1, arg2, ..... argN)
D.def <name> (<of the type> arg1, < type> arg2, ..... <type> argN)


Second, fill in the blank:

1. what function needs to reference a global variable in which k, please fill statement:
DEF Fun ()
_________ global K
K = K +. 1

2. Range = L (100)
. 1) taking a first element to the third List ___ (L [0:. 3])
2) taking the inverse of the second element or ___ ___ L [-2] or L [ 98]
3) take the ten elements List ___ (L [-10:])
. 4) to the copied L = L1 L1 List with ___ (L [:])

3. Analyzing dict there is some way with key : ____ in or get, which in this most legitimate

4. Get the number of elements in the list, and the additional element to the end of the method are ____ ____ len () append ()

output 5. the following code would be what _ ___ [10, 'A'] ___ [123] ___ [10, 'A'] __
DEF extendList (Val, List = []):
list.append (Val)
return list # returns the memory address list
List1 = extendList (10)
List2 = extendList (123, [])
list3 = extendList ( 'A')
Print ( 'List1 =% S'% List1)
Print ( 'List2 =% S '% List2)
Print (' List2 =% S '% List2)

6. the output program below is: ____ yes______

X = True
Y = False
Z = False
IF X or Y and X:
Print' Yes '
the else:
Print' no '

three short answer questions:
1. how to determine the variable is not a string
a: use the type () method if the result of print (type (variables)) is output string str is described

2.is distinction and ==
a: is the memory address comparison, the comparison is a value ==

how to achieve the conversion tupele 3.Python inside and the list
a: data type cast

4.list tuple and what is the difference
a: immutable tuple

5. how to get a list of list of intersection and set difference
A: set (list) intersection: & set difference: -

how to write variable parameters and default parameters 6.Python defined function?
A: * args, default parameters

7. * args and ** kwargs under what circumstances to use? Please give examples use ** kwargs
A: not sure how many parameters of time, args is receiving all locations of mass participation, kwargs is received in a mass participation by keyword
case is ** kwargs decorator

8. Please describe unicode the relationship between the encoding utf-8, gbk, etc.?
A: unicode: Unicode, accounting for memory
UTF -8
GBK GB code, Made in China, is not compatible with the language of other countries

9. How to delete a file using python
A: Import os
os.remove ()

10.def FUNC (A, b , * args, c = 0, ** kwargs):
Pass
What is the role * args, ** kwargs is?
A: args receiving redundant position parameter, receiving redundant keywords kwargs parameters

four write code:
1. D = { 'A':. 1, 'B': 2, 'C':}. 3, a print key, value pairs

D = { 'A':. 1, 'B': 2, 'C':. 3}
for I in D:


2. Write piece of Python code for deleting a list of repetitive elements which

method:

DEF remoc (L):
IF type (L) IS SET:
return L
the else:
L = SET (L)
return L

RET = remoc ([ 1,2,3,4,5,2,1])
Print (RET)

method two:

Lisl = [1,2,3,4,5,2,1]
new_l = []
for I in Lisl:
IF I in new_l not:
new_l.append (i)
Print (new_l)

3. Python use on aircraft to address the following topics
1) Fibonacci columns 1,2,3,5,8,13,21 ....... according to this rule, the programming is obtained within the maximum 4,000,000 Fibonacci numbers, and it is determined what number the Fibonacci

K =. 1
J = 2
Print (K, J, End = '\ T' )
SUM = 0
for I in Range (4000000) [. 3:]:
IF I == (J + K):
K = J
J = I
SUM + =. 1
Print (I, End = '\ T')
Print ( '\ n-')
Print ( 'first' + str (sum + 2) + ' th the Fibonacci columns')

2) dicta = { 'A':. 1, 'B': 2, 'C':. 3, 'D':. 4, 'F': 'Hello'}
dictb = { 'B':. 3, 'D':. 5, 'e': 7, 'm ': 9, 'k': 'world'}
after asked to write code to implement the sum of two dictionaries, the key corresponding to different values of retention, the same key value corresponding to the sum retention, splice case on the string, the results obtained for the example above:
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'}
dicl = {}
for i in dicta:
dicl[i] =dicta[i]
for j in dictb:
if i == j :
dicl[i] = dicta[i] + dictb[j]
k in dictb for:
IF k not in DICL:
DICL [k] = dictb [k]
Print (DICL)

5. What is a decorator? Write a decorator, a long time can be printed out method execution information

A:
do not want to modify the function is called, also want to extend functions, this time we need to write a decorator to function

Import Time
DEF wrapper (FUNC):
DEF Inner (* args, ** kwargs):
Start the time.time = ()
FUNC ()
Print ( 'father written prose')
End = the time.time ()
min = End - Start
return min
return Inner

@wrapper
DEF FUNC ():
the time.sleep (0.1)

RET = FUNC ()
Print (RET)

6. Please write the log to achieve (the main function is to print the function name)
@log
now DEF ():
print'2017-08-31 '

>>> now ()
Output:
Call now ():
2017-08-31

DEF log (F):
DEF Inner (* args, ** kwargs):
Print ( 'Call', F .__ name __, '():')
F ()
return Inner
@log
DEF now ():
Print ( '2017-08-31')

now ()

five additional questions:
a data structure as follows shown, write a dictionary function returns a value corresponding to the specified fields and composed of data from the structure, if the specified field does not exist, the field is skipped
data: { 'time': ' 2016-08-05T13: 13 : 05 ',
' some_id ':' id1234 ',
' grp1 ': {' FLD1 ':. 1,' FLD2 ': 2},
' GRP2 ': {' know about fld3 ': 0,' fld5 ': 0.4},
' fld6 ': 11,
'fld7':7,
'fld46':8 }

fields: the '|' connected to 'fld' at the beginning of the string, such as: FLD2 | know about fld3 | fld7 | fld19

DEF SELECT (Data, Fields):
# the TODO: Implementation
return Result

Guess you like

Origin www.cnblogs.com/if-it-is-possible/p/11518995.html