Download presentation
Presentation is loading. Please wait.
1
Python 12 Mr. Husch
2
Overview 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)
3
Name this code lastname12
4
Explanation On line 1 we have what's called an "import". This is how you add features to your script from the Python feature set. Rather than give you all the features at once, Python asks you to say what you plan to use. This keeps your programs small, but it also acts as documentation for other programmers who read your code later.
5
explanation The argv is the "argument variable", a very standard name in programming, that you will find used in many other languages. This variable holds the arguments you pass to your Python script when you run it. In the exercises you will get to play with this more and see what happens.
6
explanation Line 3 "unpacks" argv so that, rather than holding all the arguments, it gets assigned to four variables you can work with: script, first, second, and third. This may look strange, but "unpack" is probably the best word to describe what it does. It just says, "Take whatever is in argv, unpack it, and assign it to all of these variables on the left in order."
7
Test it Call your program in CMD and test that you can recall the script. Recall by: python programname.py first 2nd 3rd
8
Turn it in
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.