How to pass simple parameter in python

I want to try simple Python code where I want to pass parameter.

import sys    
result = 3 * 3 * <parameter>

When I run the Python code i want to pass value as 3 in input parameter so that i can get result 27 at the end. I can run the python code after passing the value in the parameter. For example i can run the python code like below. Is it possible to do in Python ? 3


You were pretty close with the import sys. The first command-line argument is in sys.argv[1], as a string.

import sys    
result = 3 * 3 * int(sys.argv[1])


~ > python 3

Assuming some UNIX-like system, you can run your script as a program (so ./ 3) by making it executable and adding a shebang; to run your script from everywhere (so 3), add it to your $PATH. Both of these are optional.