O'Reilly logo

Learn Python the Hard Way: A Very Simple Introduction to the Terrifyingly Beautiful World of Computers and Code, Third Edition, Video-Enhanced Edition by Zed A. Shaw

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exercise 13. Parameters, Unpacking, Variables

ImageVideo: 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 python 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 argv23    script, first, second, third = argv45    print "The script is called:", script6    print "Your first ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required