Python Interview Questions & Answers - Part 8

  • Team myQ

    29) Explain how to delete a file in Python?
    By using a command os.remove (filename) or os.unlink(filename)

    30) Explain how can you generate random numbers in Python?
    To generate random numbers in Python, you need to import command as

    • import random
    • random.random()

    This returns a random floating point number in the range [0,1)

    31) Explain how can you access a module written in Python from C?
    You can access a module written in Python from C by the following method,
    Module = =PyImport_ImportModule("");

    32) Mention the use of the // operator in Python?
    It is a Floor Division operator, which is used for dividing two operands with the result as quotient showing only digits before the decimal point.
    For instance, 10//5 = 2 and 10.0//5.0 = 2.0.