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")

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

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

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

  • 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?


  • ['arg1', 'arg2']

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

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

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

Question 3

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

  • To restart the Python interpreter.

  • To pause the program's execution indefinitely.

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

  • 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?

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

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

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

  • 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'?

  • platform.uname()

  • platform.platform()

  • platform.node()

  • 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?

  • platform.machine()

  • platform.architecture()

  • platform.python_compiler()

  • platform.processor()

Tags:

There are 6 questions to complete.

Take a part in the ongoing discussion