Skip to content
DK » Blog » Python Skill Assessment Quizzes – Part 1

Python Skill Assessment Quizzes – Part 1

1.  What happens when you use the build-in function any() on a list?

  • The any() function will randomly return any item from the list.
  • The any() function returns True if any item in the list evaluates to True. Otherwise, it returns False.
  • 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.
  • The any() function returns a Boolean value that answers the question “Are there any items in this list?”

2.  What statement about static methods is true?

  • Static methods are called static because they always return None.
  • Static methods can be bound to either a class or an instance of a class.
  • Static methods serve mostly as utility methods or helper methods, since they can’t access or modify a class’s state.
  • Static methods can access and modify the state of a class or an instance of a class.

3.  What built-in list method would you use to remove items from a list?

  • .delete() method
  • pop(my_list)
  • del(my_list)
  • .pop() method

4.  What is the correct syntax for defining a class called Game, if it inherits from a parent class called LogicGame?

  • class Game(LogicGame): pass
  • def Game(LogicGame): pass
  • def Game.LogicGame(): pass
  • class Game.LogicGame(): pass

5.  What built-in Python data type is commonly used to represent a stack?

  • set
  • list
  • None
  • dictionary
  • You can only build a stack from scratch.

6.  What is the purpose of the “self” keyword when defining or calling instance methods?

  • self means that no other arguments are required to be passed into the method.
  • There is no real purpose for the self method; it’s just historic computer science jargon that Python keeps to stay consistent with other programming languages.
  • self refers to the instance whose method was called.
  • self refers to the class that was inherited from to create the object using self.

7.  What does the built-in map() function do?

  • It creates a path from multiple values in an iterable to a single value.
  • It applies a function to each item in an iterable and returns the value of that function.
  • It converts a complex value type into simpler value types.
  • It creates a mapping between two different elements of different iterables.

8.  When does a for loop stop iterating?

  • when it encounters an infinite loop
  • when it encounters an if/else statement that contains a break keyword
  • when it has assessed each item in the iterable it is working on or a break keyword is encountered
  • when the runtime for the loop exceeds O(n^2)

9.  What happens when you use the built-in function all() on a list?

  • The all() function returns a Boolean value that answers the question “Are all the items in this list the same?
  • The all() function returns True if all the items in the list can be converted to strings. Otherwise, it returns False.
  • The all() function will return all the values in the list.
  • The all() function returns True if all items in the list evaluate to True. Otherwise, it returns False.

10.  What is the definition of abstraction as applied to object-oriented Python?

  • Abstraction means that a different style of code can be used, since many details are already known to the program behind the scenes.
  • Abstraction means the implementation is hidden from the user, and only the relevant data or information is shown.
  • Abstraction means that the data and the functionality of a class are combined into one entity.
  • Abstraction means that a class can inherit from more than one parent class.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.