Python Interview questions - functions
(Python version 3.9 or later version)
Which of the following python statements will not be ignored by python interpreter, but the interpreter does nothing at run time as the intended use of the statement is to act as a stand-in or placeholder?
def f9():
    '''This is a docstring'''
    # This is a comment
    pass
    yield
'''This is a docstring'''
# This is a comment
pass
yield
Python Interview Questions
  • Python - Functions
    1. What function is used to accept user input?
    A) print()
    B) input()
    C) cin

    Answer: input()
    2. How does the input function decide when the user has finished inputting data?
    A) A space is reached
    B) It reaches a newline
    C) The user says so

    Answer: It reaches a newline
    3. What function is used to split user data into multiple values?
    A) break
    B) print
    C) split

    Answer: split
    4. You define you are creating a function with what keyword?
    A) func
    B) def
    C) new

    Answer: def
    5. You can return a value from a function with what keyword?
    A) end
    B) go
    C) return

    Answer: return
    6. A variable defined in a function is available outside the function (T or F)?
    A) True

    B) False
    Answer: False
    7. Changes to global variables in functions effect that variable outside of the function (T or F)?
    A) True
    B) False

    Answer: False
    8. You define that you want to effect a global variable in a function with what keyword?
    A) global
    B) gbl
    C) var

    Answer: global
    9. To return multiple values from a function we separate values with?
    A) commas
    B) spaces
    C) semicolons

    Answer: commas
    10. To accept an unknown number of arguments in a function we proceed an argument with what?
    A) +
    B) #
    C) *

    Answer: *
    11. What function is called each time you create a new object?
    A) new
    B) constructor
    C) init

    Answer: init
    12. What keyword is used to a class when an object wants to refer to itself?
    A) this
    B) self
    C) that

    Answer: self
    13. How would the object spot call for the bark function to execute?
    A) bark()
    B) this.bark()
    C) self.bark()

    Answer: self.bark()
    14. What keyword do we use to define any call to a field will execute a function?
    A) @property
    B) @staticmethod
    C) self

    Answer: @property
    15. What keyword would be used to define height as a setter?
    A) @setter height
    B) @height.setter
    C) @height

    Answer: @height.setter
    16. What decorator is used to define a getter method?
    A) @getter
    B) @property
    C) @staticmethod

    Answer: @property
    17. How do you define that birth_type is a setter?
    A) @birth_type.setter
    B) @setter.birth_type
    C) @setter birth_type

    Answer: @birth_type.setter
    18. Method used to cast our object to a string?
    A) str
    B) _str_
    C) string

    Answer: _str_
    19. Function used to count the number of matching values in a list?
    A) count
    B) find
    C) len

    Answer: count
    20. Function used to execute code on each item in a list?
    A) filter
    B) reduce
    C) map

    Answer: map
    21. Function that selects items from a list based on an exception?
    A) filter
    B) reduce
    C) map

    Answer: filter
    22. Function used to receive a list and return a single result?
    A) filter
    B) reduce
    C) map

    Answer: reduce
    23. Function used to convert a string into an iterator?
    A) iterator
    B) iter
    C) next

    Answer: iter
    24. Function used to pull data from an iterator?
    A) get
    B) next
    C) getter

    Answer: next
    25. What function is used to search for a match in a string?
    A) re.search
    B) re.find
    C) re.get

    Answer: re.search
    26. What function returns a list of matches?
    A) re.getall
    B) re.searchall
    C) re.findall

    Answer: re.findall
    27. What function returns an iterator of matching objects?
    A) re.getiter
    B) re.finditerator
    C) re.finditer

    Answer: re.finditer
    28. What function returns a tuple that contains the starting and ending index for a regular expression match?
    A) findall
    B) span
    C) search

    Answer: span
    29. What function is used to create a pattern object?
    A) re.compile
    B) re.pattern
    C) re.regex

    Answer: re.compile
    30. What function is used to substitute a string with a regular expression match in another string?
    A) replace
    B) findReplace
    C) sub

    Answer: sub
    31. What function is used to substitute a string with a regular expression match in another string?
    A) replace
    B) findReplace
    C) sub

    Answer: sub
    32. What argument do you use with functions to receive a keyworded variable length of arguments?
    A) *args
    B) *kwargs
    C) **kwargs

    Answer: **kwargs
    33. Keyword used to define an anonymous function?
    A) def
    B) lambda
    C) func

    Answer: lambda
    34. Keyword used to define an anonymous function?
    A) def
    B) lambda
    C) func

    Answer: lambda
  • gk