Skip to content
Snippets Groups Projects

add jupyter notebook for python mistakes meeting

Merged Jelle Scholtalbers requested to merge scholtal/EPUG:python_mistakes into master
3 files
+ 68
1
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 53
0
%% Cell type:code id: tags:
``` python
# this can be a shortcut to assign None to multiple variables
x = y = z = None
z = 1
print(x,y,z)
```
%% Output
(None, None, 1)
%% Cell type:code id: tags:
``` python
# BAD: this is probably not what you wanted
u = i = o = []
o.append("x")
print(u,i,o)
```
%% Output
(['x'], ['x'], ['x'])
%% Cell type:code id: tags:
``` python
# BAD: the original list you pass to the method will get updated!
def my_method(mutable_list=[]):
mutable_list.append('x')
return mutable_list
# a list out of the my_method scope
a_list = ['a']
b_list = my_method(mutable_list=a_list)
# a_list get modified!
print( a_list == b_list, a_list, b_list )
```
%% Output
(True, ['a', 'x'], ['a', 'x'])
%% Cell type:code id: tags:
``` python
```
Loading