When in the function definition, these 'slots' are called
later on, in your code, when you call the function, the actual values that you pass to the function call are called
Please refer to python glossary for in-depth definition of arguments and parameters
Also, check the FAQ on What is the difference between arguments and parameters?
All that said - couple of things regarding your code. Your examples are perfectly valid code and many people would do it the same way. all of your examples are using positional arguments. It's more clear and easy to follow the code if you get the habit to pass named/keyword arguments. e.g.
also you can have default values, e.g
Finally - you are using print statements and old style string formatting in your print statements. So you are using python2 and as a newbie, starting now to learn python you should start learning python3 (latest one in python 3.6). In python3 print is a function, not statement.
I assume you study python2 because of the book, but I would recommend to find a book that is based on python3. There is even LPTHW version for python3, but Learn python the hard way is really controversial textbook, and one of the reasons is exactly because of using such terms as 'slots', while there are accepted terms in the programming.
As to the string formatting, instead of
https://docs.python.org/3.6/library/stri...ing-syntax
parameters
, e.g.def cheese_and_crackers(cheese_count, boxes_of_crackers)function
cheese_and_crackers
has two parameters - cheese_count
and boxes_of_crackers
later on, in your code, when you call the function, the actual values that you pass to the function call are called
arguments
. In thischeese_and_crackers(20, 30)20 and 30 are arguments. There are positional and named or keyword arguments.
Please refer to python glossary for in-depth definition of arguments and parameters
Also, check the FAQ on What is the difference between arguments and parameters?
All that said - couple of things regarding your code. Your examples are perfectly valid code and many people would do it the same way. all of your examples are using positional arguments. It's more clear and easy to follow the code if you get the habit to pass named/keyword arguments. e.g.
cheese_and_crackers(cheese_count=20, boxes_of_cracker=30)or
cheese_and_crackers(cheese_count=amount_of_cheese,boxes_of_cracker=amount_of_crackers)you can mix positional and named arguments, however positional arguments ALWAYS come before the named arguments. i.e. you cannot have positional arguments after you have supplied named arguments.
also you can have default values, e.g
def cheese_and_crackers(cheese_count=20, boxes_of_crackers=30)and then call the function just like
cheese_and_crackers()and it will use the default values. Of course you can pass one argument and use the default value for the other, etc.
Finally - you are using print statements and old style string formatting in your print statements. So you are using python2 and as a newbie, starting now to learn python you should start learning python3 (latest one in python 3.6). In python3 print is a function, not statement.
I assume you study python2 because of the book, but I would recommend to find a book that is based on python3. There is even LPTHW version for python3, but Learn python the hard way is really controversial textbook, and one of the reasons is exactly because of using such terms as 'slots', while there are accepted terms in the programming.
As to the string formatting, instead of
print "You have %d cheeses!" % cheese_count print "You have %d boxes of crackers!" % boxes_of_crackersit is better to use
print("You have {} cheeses!".format(cheese_count)) print("You have {} boxes of crackers!".format(boxes_of_crackers))or in python3.6 you can use the new formatted strings
print(f"You have {cheese_count} cheeses!") print(f"You have {boxes_of_crackers} boxes of crackers!")to read more on string formatting check this
https://docs.python.org/3.6/library/stri...ing-syntax