T
Tobias Weber
Hi,
being new to Python I find remarkable that I don't see any side effects.
That's especially true for binding. First, it is a statement, so this
won't work:
if x = q.pop():
print x # output only true values
Second, methods in the standard library either return a value OR modify
the reciever, so even if assignment was an expression the above wouldn't
work.
Only it still wouldn't, because IF is a statement as well. So no ternary:
x = if True: 5 else: 7;
However there is one bit of magic, functions implicitly return None. So
while the following will both run without error, only one actually works:
x = 'foo'.upper()
y = ['f', 'b'].reverse()
Now I mentioned that the mutable types don't have functions that mutate
and return something, so I only have to remember that...
But I'm used to exploiting side effect, and sometimes forget this rule
in my own classes. IS THERE A WAY to have the following produce a
runtime error?
def f():
x = 5
# no return
y = f()
Maybe use strict
being new to Python I find remarkable that I don't see any side effects.
That's especially true for binding. First, it is a statement, so this
won't work:
if x = q.pop():
print x # output only true values
Second, methods in the standard library either return a value OR modify
the reciever, so even if assignment was an expression the above wouldn't
work.
Only it still wouldn't, because IF is a statement as well. So no ternary:
x = if True: 5 else: 7;
However there is one bit of magic, functions implicitly return None. So
while the following will both run without error, only one actually works:
x = 'foo'.upper()
y = ['f', 'b'].reverse()
Now I mentioned that the mutable types don't have functions that mutate
and return something, so I only have to remember that...
But I'm used to exploiting side effect, and sometimes forget this rule
in my own classes. IS THERE A WAY to have the following produce a
runtime error?
def f():
x = 5
# no return
y = f()
Maybe use strict