And the function code reuse --Python

1, a description of the recursive function, the following options are correct

Contains a loop structure A.
B. complex function
inside C. function contains calls this function again
D. function name as a return value

Answer: D
Answer Analysis: recursive function again refers to the internal function contains a call to this function.

2, description of the embodiment of the recursive function group, the following error is

A. recursive functions must embodiment yl
group B. Example no recursive function recursively
C. Each recursive function can only have one group in Example
D. Example yl recursive function determines the depth of recursion

Answer: C
Answer Analysis: recursive functions of each embodiment that at least one group

3, the following options, not part of the role is to function

Increase the speed of execution of code A.
B. code reuse
C. enhance readability of the code
D. reducing programming complexity

Answer: C
Answer Analysis: function returns a code reuse, enhance code readability, reduce programming complexity, but does not increase the execution speed of the code.

4, assuming that the function is not included in global reserved word, a method for changing parameter values, the following error is

A. Type parameter is a list, change the original value of the parameter
B. is an integer parameter type, the parameter does not change the value of the original
C. parameter type is a combination of (an object variable), to change the original value of the parameter
value of the parameter D. whether to change the operation functions related to the object, regardless of the type of the parameter

Answer: D
Answer Analysis: python, there are sub-variable objects and immutable object of. Only incoming is immutable, it does not change the value, if an object variable, the value of the incoming note. Immutable objects: Number, String, Tuple, bool . Mutable objects: List, Set, Dictionary internal elements can be changed.

5, in python, description of the function, the following options are correct

A. A function allows only one return statement

In B. Python, and DEF functions must return reserved words are used in
C. Python no defined function parameter specified type, which shows that the parameters in the function of any type can be used as
D. function eval () values may be used an expression, for example, eval ( '2 * 3 + 1 ')

Answer: D
Answer Analysis: function may not use the return statement or return statement, so A, B incorrect; Python does not specify the type of parameter defined functions, the function should be used based on the type of arguments, C is incorrect.

6, the following code is given
def func(a,b):
    c = a **2 + b
    b =a
    return c
a =10
b =100
c = func(a,b)+a

The following options are describing the error

A. After executing the function, the value of variable c 200

B. The name of the function func
after execution of the function C., the value of variable b 100
D. After executing the function, the variable a is 10

Answer: A
Answer Analysis: After performing this function, the value of variable c 210

7, in Python, on the global and local variables, the following options are not correctly describe

A. a variable in the program contains two types: global and local variables
B. Usually the global variable is not indented
C. valid global variables during program execution in the whole
D. global variables and local variables can not be the same name

Answer: D
Answer Analysis: local variables and global variables can be the same name, a global variable is a variable defined refers to outside of the function, the program performs the entire process effective. When global variables inside a function, it is required in advance using the reserved word global statement. It refers to the local variable variables inside a function definition, only valid within the function, when the function exits, the variable is no longer present. E.g:

n =2
def multiply(x, y =10):
    n =x*y     #局部变量n,和第一行代码n不同。
    return n   #返回的n也是局部变量n
s =multiply(99,2)
print(s)
print(n)

Local variables and global variables can be the same name, so the error D

8, on process-oriented and object-oriented programming description, the following options are correct

A. Object-oriented programming is more advanced than process-oriented programming

B. process-oriented and object-oriented programming languages are classified according to
C. modular design of object-oriented design is
D. all the features of object-oriented programming can be achieved using the same process can be completed for

Answer: D
Answer Analysis: Function object-oriented programming can be used to achieve both facing the same process can be completed

9, the following options, for a description of the error is recursive procedure

A. write simple

High efficiency B.
C. must be yl embodiment
may be prepared with a non-recursive method of recursive procedure D.

Answer: B
Answer Analysis: recursive procedure execution efficiency is relatively low

10, the output of the following code is
 f = lambda x,y:y+x
 f(10,10)

A. 10

B. 20
C.10,10
D.100

Answer: B
Answer Analysis: lambda expression is equivalent to:

def fun(x, y):
    return x + y
print(fun(10, 10))
11, a description of the parameter and the parameter, the following options are correct

A. Definitions function parameter list is inside the parameters of the actual parameter, referred to as the argument
B. given argument list to be passed within the parameters of the function, such parameters called formal parameters, referred to as the parameter
when the program is invoked C., the arguments to the function parameter copy
D. in the call, the parameter argument function to copy

Answer: C
Answer Analysis: function definition inside the parameter list given parameter is a parameter, the parameter list passed to function within the parameters, such parameters called real parameters; in the call, the arguments to a function to copy the parameter

12, on lambda functions, the following options are describing the error

A. lambda function is also known as anonymous functions

B. lambda function will return as a function of the result of the function name
C. defines a special function
D.lambda not a Python reserved word

Answer: D
Answer Analysis: lambda is a reserved word in Python

13, the following options for the function definition is wrong

A. def vfunc(a, b = 2):

B. def vfunc(a, b):
C. def vfunc(a, b):
D. def vfunc(
a, b):

Answer: D
Answer Analysis: def vfunc (* a, b ): * ( optional) should be placed in the back, so the error D

14, a function of the parameters, the following options are describing the error

A. defining a function, if there is a default value of some parameters can be specified when the default value is defined as a function of these parameters directly

B. defining a function, a variable number of parameters can be designed, by increasing the parameter before the asterisk (*)
C. Optional parameters may be defined in front of the non-optional parameters
D. be passed to a tuple with a star variable number of parameters

Answer: D
Answer Analysis: Optional parameters can not be defined in the previous non-optional parameters

15, on the return statement, the following options are correct is

A. function can only have one return statement
B. function must have a return statement
C.return can return only one value
D. function can not return statement

Answer: D
Answer Analysis: functions return the number is not limited, and there is no return statement

16, with regard to function, the following options are describing the error

A. function is a piece having a specific function, reusable statement group
B. function to complete a specific function, you do not need to understand the use of the internal functions of function realization principle, as long as the understanding of the function input and output to
C. Using Function The main purpose is to reduce the difficulty of programming and code reuse
D.Python del reserved words defined using a function

Answer: D
Answer Analysis: Python use the reserved word def definition of a function

17, about the Python global and local variables, the following options are describing the error

A. global variable refers to the variable outside the function definition, the general is not indented, the whole process of the implementation of the program effectively
B. local variable refers to the use of variables inside a function, when the function exits, the variable still exists, the next function call can continue to use
the reserved word C. using global declarations simple data type variable, which is used as a global variable
D. simple data types, variables and global variables, whether or not the same name, only to create and use within the function, the function exits the variable is released

Answer: D
Answer Analysis: refers to the local variable variables inside a function definition, only valid within the function, when the function exits, the variable is no longer present.

18, on the Python lambda function, the following options are describing the error

A.lambda a simple definition, the function can be represented by the line
B. lambda principles can be used to sort the list of defined function
Cf = lambda x, y: x + y after execution, f is the type of a digital type
D.lambda function the function name returned as the function result

Answer: D
Answer Analysis: C options, f is determined according to the type of the parameter

19, the following code to implement the functions described
def fact(n):
    if n == 0:
        return 1
    else :
        return n * fact(n-1)
num = eval(input('请输入一个整数:'))
print(fact(abs(int(num))))

A. accept user input integer N, the output value of the N factorial

B. integer N accepts user input, it is determined whether N is a prime number and outputs Conclusion

C. accepts user input integer N, N is an integer, and determines whether the output conclusions

D. accepts user input integer N, to determine whether N is the number of daffodils
answer: D
Answer Analysis: This is a typical recursive function, call the function itself in the return statement. N factorial function output value

20, the following code is given
def fact(n):
    s = 1
    for i in range(1,n+1):
        s *= i
  return s

The following is a description of the error option
A. code n is an optional parameter
B.fact (n) is a function-factorial of n -
Cs is a local variable
D.range () function is a built-in function Python

Answer: A
Answer Analysis: code n is not optional parameters, optional parameters * or **

21, the following code is given
ls = ['car','truck']
def funC(a):
    ls.append(a)
    return
funC('bus')
print(ls)

The following is a description of the error option
A.ls.append (a) code is a global variable ls
B. execution code output is [ 'CAR', 'Truck']
C.ls.append (A) code ls is a list of variable types
D.funC (a) in a non-optional parameters

Answer: B
Answer Analysis: executing code output is [ 'car', 'truck' , 'bus']

22, the following code is given
ls = ['car','truck']
def funC(a):
    ls = []
    ls.append(a)
    return
funC('bus')
print(ls)

The following is a description of the error option
A. code function definitions, ls.append (a) the local variable ls
result of execution of the code is output B. [ 'CAR', 'Truck']
C.ls.append (A ) is a list of the code type ls
D. execution code output is [ 'car', 'truck' , 'bus']

Answer: D
Answer Analysis: ls function inside the funC local variables, global variables, at the end of the function call, local variables will disappear. Ls the final printed output is a global variable.

23, the following code is given
import turtle
def drawLine(draw):
    turtle.pendown() if draw else turtle.penup()
    turtle.fd(50)
    turtle.right(90)
drawLine(True)
drawLine(True)
drawLine(True)
drawLine(True)

The following is a description of the error option
A. running code in the Python Turtle Graphic, draw a square
B. Code def drawLine (draw) can draw the values True and False
C. codes the drawLine (True) True replace the - 1, the results of running the code unchanged
D. codes the drawLine (True) True replace the 0 code running results unchanged

Answer: D
Answer Analysis: if else shorthand for example:

a, b, c = 1, 2, 3
if a > b:
    c = a
else:
    c = b

It can be abbreviated as:

a, b, c = 1, 2, 3
c = a if a > b else b

Boolean parameters if necessary, the input is numeric, then only the number of non-0 value, the corresponding is True, if the input value of 0 represents False, so incorrect D

24, the following code is given
import turtle
def drawLine(draw):
    turtle.pendown() if draw else turtle.penup()
    turtle.fd(50)
    turtle.right(90)
drawLine(True)
drawLine(0)
drawLine(True)
drawLine(True)
turtle.left(90)
drawLine(0)
drawLine(True)
drawLine(True)

The following is a description of the error option
A. running code in the Python Turtle Graphic, draw a digital number 2
B. codes the drawLine (True) True replace the 0 code running results unchanged
C. codes the drawLine (True) of Alternatively -1 True, the same operation results of code
D. codes def drawLine (draw) can draw the values 0, 1, etc.
answer: B
answer Analysis: Boolean parameters if necessary, the value is inputted, it requires only the number of non-0 value, the corresponding is True, if the input value is 0, it represents False.

25, the result of the following code is run
def func(num):
    num += 1
a = 10
func(a)
print(a)

A.10
B.11
C. error
D.int

Answer: B
Answer Analysis: function when passing parameters, it means to copy parameter argument, the argument itself not to change.

26, operation of the following code is
def func(a, b):
    return a >> b
s = func(5, 2)
print(s)

A.20
B.6
C.1
D.12

Answer: C
Answer Analysis: Represents a >> b will be converted to a binary, and then move the b bits to the right, (<< represents the left, >> represents the right). a = 5, of binary 101; b = 2, that is, 2 101 moves to the right, to 1.

27, operation of the following code
def func(a, b):
    a *= b
    return a
s = func(5, 2)
print(s)

A. 20 B. 10 C. 1 D. 12

Answer: B

28, operation of the following code is
def f2(a):
    if a > 33:
        return True
li = [11, 22, 33, 44, 55]
res = filter(f2, li)
print(list(res))

A.[44,55]
B.[33,44,55]
C.[22,33,44]
D.[11,33,55]

Answer: A
Answer Analysis: filter () function is a built-in Python Another useful higher order function, filter () function is a function f and a reception list, the action in question in this function f2 is judged whether or not each element 33 is greater than, returns True if greater than or False, filter () automatically filters out elements meet the conditions according to the judgment result, i.e. returns the new list consisting of elemental True, so this choice question A. Note, res object type.

Guess you like

Origin www.cnblogs.com/qikeyishu/p/10985771.html