What is the difference between sys.argv and input() in Python?

91 views

What is the difference between sys.argv and input() in Python?

What is the difference between sys.argv and input() in Python?

solveurit24@gmail.com Changed status to publish February 13, 2025
0
  • sys.argv: Access command-line arguments passed to the script.
  • input(): Read input from the user during runtime.

Example:

import sys

# Using sys.argv
# Run the script as: python script.py arg1 arg2
print(sys.argv)  # Output: ['script.py', 'arg1', 'arg2']

# Using input()
user_input = input("Enter something: ")
print(f"You entered: {user_input}")

solveurit24@gmail.com Changed status to publish February 13, 2025
0