Calvin (Deutschbein)
W10Wed: 30 Oct
"".join("hi","world") # this works
join("hi","world") # this doesn't
"".len("hi") # this doesn't
len("hi") # this does
a, b = [1], [1]
c = b
c is b, c == b # True, True
c is a, c == a # False, True
>>> list, type(list)
(<class 'list'>, <class 'type'>) # a class
>>> list(), type(list()) # an object
([], <class 'list'>)
>>> def do_thing():
... 1 == 1
...
>>> type(do_thing)
<class 'function'>
>>> do_thing
<function do_thing at 0x00000298D0845120>
class Box:
pass
class Box:
pass
>>> b = Box()
class Box:
pass |
def boxify():
return |
class XBox:
# turn 360 walk away
x = 360 |
def xboxify():
# I'm so Julia
x = 360 |
b = XBox()
print(b.x) # prints 7 |
b = xboxify()
print(b.x) # error |
>>> class XBox:
... x = 360
... return x
...
File "<stdin>", line 3
SyntaxError: 'return' outside function |
>>> def xboxify():
... x = 360
... return x
...
>>> xboxify()
360 |
class XBox:
x = 360 |
def xboxify():
x = 360
return x |
b = XBox()
b.x = 1
print(b.x) # prints 1 |
x = 1
b = xboxify()
print(b) # prints 360
|
class XBox:
# loneliest #
x = 1 |
def xboxify():
# we are # 1
x = 1 |
b = XBox(1) |
b = xboxify(1) |
class XBox:
def __init__(self, val):
x = val |
def xboxify(val):
x = val
return x |
b = XBox(1)
b.x # is 1 |
b = xboxify(1)
b # is 1 |
class XBox:
def __init__(self, val):
x = val
class XBox:
def __init__(self, val):
x = val
class XBox:
def __init__(self, val):
x = val
class XBox:
def __init__(self, val):
x = val
>>> __init__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name '__init__' is not defined
class XBox:
def __init__(self, val):
x = 1
print(x)
x = val
print(x)
>>> b = XBox(360)
1
360
>>> b.x
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'XBox' object has no attribute 'x'
class XBox:
def __init__(self, val):
self.x = 1
print(self.x)
self.x = val
print(self.x)
>>> b = XBox(9)
1
360
>>> b.x
360
class XBox:
x = 360
def __init__(self, val):
print(self.x)
self.x = val
print(self.x)
>>> b = XBox(1)
360
1
>>> b.x
1