- #1
Mogarrr
- 120
- 6
I'm reading the online tutorial "How to Think Like a Computer Scientist", which is a Python tutorial. There is an exercise, which I'm trying to figure out.
What happens if you call a function and you don't do anything with the result (i.e., you don't assign it to a variable or use it as part of a larger expression)?
My intuition is that nothing happens. To show this, I typed the following in the command line...
def nada(something):
nil = something
As predicted, when I call the function nada, nothing happens. Is this what the author meant by doing nothing with the result?
Experimenting with functions, I also discovered something that disturbs me about Python. I made a function...
def makeSix(number):
number = 6
Now I would think that the makeSix function will change the value of a variable to 6. For instance, I typed this:
x = 9
makeSix(x)
print x
9
Which is frustrating, since I would think that the value of the variable would change to 6.
What's going on?
What happens if you call a function and you don't do anything with the result (i.e., you don't assign it to a variable or use it as part of a larger expression)?
My intuition is that nothing happens. To show this, I typed the following in the command line...
def nada(something):
nil = something
As predicted, when I call the function nada, nothing happens. Is this what the author meant by doing nothing with the result?
Experimenting with functions, I also discovered something that disturbs me about Python. I made a function...
def makeSix(number):
number = 6
Now I would think that the makeSix function will change the value of a variable to 6. For instance, I typed this:
x = 9
makeSix(x)
print x
9
Which is frustrating, since I would think that the value of the variable would change to 6.
What's going on?