The sys module in Python gives you direct access to interpreter-level functions, environment details, command-line arguments, I/O streams, and system-specific parameters.
sys.argvYou need to import the module before using any of its properties or functions:
import sys
print(sys.version) # Python version
print(sys.platform) # OS platform
# Save as example.py
import sys
print(sys.argv) # List of command line arguments
sys.stdout.write("Hello World\n") # Write to standard output
sys.stderr.write("This is an error message\n") # Write to standard error stream
print(sys.path) # List of directories Python searches for modules
sys.exit() # Exit with default status code 0
sys.exit(1) # Exit with a custom error code
sys.argv returns a list of command-line arguments where index 0 is the script name.sys.stdout writes text directly to the console.sys.stderr is typically shown in red in terminals and used for error logging.sys.path helps you debug module import errors.sys.exit() stops the script immediately.sys.argv to manage command-line tools and scripts.sys.path is very helpful when debugging import issues.sys.exit().sys.stdout and sys.stderr to files for logging purposes.sys.stdout to a file and write some text.sys.version and sys.platform.