Loading

Python——领英题库

Python

1、What is the purpose of the self keyword when defining calling methods on an instance of an object?
**
A、self means that no other arguments are required to be passed into the method.
B、There is no real purpose for the self method.It is legacy computer science jargon that Python keeps to stay consistent with other programming lang es.
C、self refers to the instance whose method was called.
D、self refers to the class that was inherited from to create the object using self.


Answer: C
2、What is a static method?
**
A、They serve mostly as utility methods or helper methods,since they can't access or modify a class's state.
B、Static methods can access and modify the state of a class or an instance of a class.
C、Static methods can be bound to either a class or an instance of a class.
D、Static methods are called static because they always return None.
**
Answer: D
3、What are attributes?
**
A、Attributes are a long-form version of an if/else statement,used when testing for equality between objects.
B、Attributes are strings that describe characterie of a class.
C、Attributes are a way to hold data or describe a state for a class or an instance of a class.
D、Function arguments are called"attributes"in the context of class methods and instance methods.

Answer: C
**
4、What is runtime complexity?
**
A、the amount of time it takes an algorithm to complete a task as a function of the size of the input
B、the difficulty level your code is written at
C、a measure of how many advanced computer programming concepts you used in your code
D、how long it will take your program to run,in microseconds
**
Answer: A
**
5、When would you use a for loop?
**
A、only in some situations,as loops are used only for certain types of programming
B、when you want to minimize the use of strings in your code
C、when you want to run code in one file for a function in another file
D、when you need to check every element in an iterable of known length

Answer: D
**
6、What is the proper way to write a list comprehension that represents all the keys in this dictionary?
fruits={
Apples':5,
'Oranges':3,
'Bananas':4
}
**
A、fruit_names=for x in fruits.keys0
B、fruit names=xfor x in fruits.keys0
C、fruit_names=[x in fruits.keys()for x]
D、fruit_names=[x for x in fruits.keys()]

Answer: D
**
7、What does a class's_init_()method do?
**
A、The_init_()method is a constructor method that is called automatically whenever a new object is created from a class.It sets the initial state of a new object.
B、The_init_method initializes any imports you may have included at the top of your file.
C、The_init_method is included to preserve backwards compatibility from Python 3 to Python 2,but no longer needs to be used in Python 3.
D、The_init_method makes classes aware of each other if more than one class is defined in a single code file.

Answer: A
**8、what value would be returned by this check for equality?
**
5 != 6
**
A、True
B、False
C、yes
D、None

Answer: A
**
9. What built-in list method would you use to remove items from a list?
**
A、delete()
B、del(my_list)
C、pop(my_list)
D .pop()
**
Answer: D

10、 What happens when you use the built-in function any() on a list?
**
A、The any() function returns a Boolean value that answers the question “Are there any items in the list?”
B、 The any() function will randomly return any item from the list.
C、The any() function returns True if any item in the list evaluates to True. Otherwise, it returns False.
D、 The any() function takes as arguments the list to check inside, and the item to check for. If “any” of the items in the list match the item to check for, the function returns True.
Answer: C

11、 What is an instance method?
**
A、An instance method is a regular function that belongs to a class, but it must return None.
B、An instance method is any class method that doesn’t take any arguments.
C、Instance methods hold data related to the instance
D、Instance methods can modify the state of an instance or the state of the parent class
**
Answer: C

12.、What is the runtime complexity of accessing a value in a dictionary by using its key?
**
A、O(1), also called constant time
B、 O(n), also called linear time
C、 O(log, n), also called logarithmic time
D、O(n2), also called quadratic time
**
Answer: A

13、Which statement does NOT describe the object-oriented programming concept of encapsulation?
**
A、 It keeps data and the methods that can manipulate that data in one place.
B、 It only allows the data to be changed by methods.
C、It protects the data from outside interference.
D、A parent class is encapsulated and no data from the parent class passes on to the child class.
**
Answer: D

14、What is the correct way to write a doctest?

** A、**
def sum(****a,b):
###
>>>sum(4,3)
**7
>>>sum(-4,5)
1
###
return a+b
**
B、
def sum(a,b):
''''''
sum(4,3)
7
>>>sum(-4,5)
1
''''''
return a+b
**
C、
def sum(a,b):
''''''
>>>sum(4,3)
**7
>>>sum(-4,5)
1
''''''
return a +b
**
**
D、
def sum(a,b):
#>>>sum(4,3)
#7
#>>>sum(-4,5)
#1
return a +b
**
Answer: D
**
15、Given the following three lists, how would you create a new list that matches the desired output printed below?

f****ruits=['apples','oranges','bananas']
quantities=[5,3,4]
prices=[1.50,2.25,0.89]
#Desired output
[('Apples',5,1.50),
('Oranges',3,2.25),
('Bananas',4,0.89)]
**
A、
output=[]
fruit_tuple_0=(fruits[0],quantities[0],price[0])
output.append(frui_tuple)
fruit_tuple_1=(fruits[1],quantities[1],price[1])
output.append(frui_tuple)
fruit_tuple_2=(fruits[2],quantities[2],price[2])

return output

posted @ 2021-01-27 15:19  坚果Leo  阅读(248)  评论(0)    收藏  举报