Python Modules os, sys and platform

Last Updated :
Discuss
Comments

Question 1

What is the key difference between os.mkdir("path") and os.makedirs("path")

  • A

    os.mkdir() can create multiple directories at once, while os.makedirs() can only create one.

  • B

    os.makedirs() can create intermediate directories recursively, while os.mkdir() cannot.

  • C

    os.mkdir() will not raise an error if a directory exists, but os.makedirs() will.

  • D

    There is no functional difference; os.makedirs() is just an alias for os.mkdir().

Question 2

If you run a script from your terminal like this: python my_script.py arg1 arg2, what will sys.argv contain?


  • A

    ['arg1', 'arg2']

  • B

    ['my_script.py', 'arg1', 'arg2'] (correct)

  • C

    ['python', 'my_script.py', 'arg1', 'arg2']

  • D

    ('my_script.py', 'arg1', 'arg2')

Question 3

What is the primary purpose of the sys.exit() function?

  • A

    To restart the Python interpreter.

  • B

    To pause the program's execution indefinitely.

  • C

    To raise a SystemExit exception and terminate the program. (correct)

  • D

    To return to the beginning of the script's main function.

Question 4

You have a file at "C:/docs/report.txt". Which function call correctly deletes this file?

  • A

    os.rmdir("C:/docs/report.txt")

  • B

    os.delete("C:/docs/report.txt")

  • C

    os.remove("C:/docs/report.txt")

  • D

    os.path.remove("C:/docs/report.txt")

Question 5

Which platform module function would you use to get a simple string identifying the operating system, such as 'Windows', 'Linux', or 'Darwin'?

  • A

    platform.uname()

  • B

    platform.platform()

  • C

    platform.node()

  • D

    platform.system()

Question 6

You need to check if your script is running on a 64-bit version of Python. Which function is best suited for this task?

  • A

    platform.machine()

  • B

    platform.architecture()

  • C

    platform.python_compiler()

  • D

    platform.processor()

Tags:

There are 6 questions to complete.

Take a part in the ongoing discussion