Exercise 13. Parameters, Unpacking, Variables
In this exercise we will cover one more input method you can use to pass variables to a script (script being another name for your .py
files). You know how you type python3.6 ex13.py
to run the ex13.py
file? Well the ex13.py
part of the command is called an argument. What we’ll do now is write a script that also accepts arguments.
Type this program and I’ll explain it in detail:
ex13.py
1 from sys import argv 2 # read the WYSS section for how to run this 3 script, first, second, third = argv 4 5 print("The script is called:", script) 6 print("Your first variable is:", first) 7 print("Your second variable is:", second) 8 print("Your third variable ...
Get Learn Python 3 the Hard Way: A Very Simple Introduction to the Terrifyingly Beautiful World of Computers and Code now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.