18 KiB
18 KiB
In [ ]:
s = 'hello'
s.upper()In [ ]:
l = [4,2,1]
l.sort()
lIn [ ]:
class Person(object):
def __init__(self, name):
self.name = name
def say_hello(self):
print("Hello, my name is " + self.name)In [ ]:
tom = Person('Tom')
tom.say_hello()In [ ]:
tom = Person('Tom')In [ ]:
tom = Person('Tom')
print(tom.name)In [ ]:
tom.say_hello()In [ ]:
Person.say_hello(tom)In [ ]:
alice = Person("Alice")
bob = Person("Bob")
alice.say_hello()
bob.say_hello()In [ ]:
alice = Person("Alice")
print (str(alice))
aliceIn [ ]:
class Person(object):
def __init__(self, name):
self.name = name
def __str__(self):
return "The Person {}".format(self.name)
def __repr__(self):
return "{}({})".format(self.__class__.__name__,
repr(self.name))
def say_hello(self):
print("Hello, my name is " + self.name)
def say_hello_to(self, other):
print("Hello " + other.name + ", my name is " + self.name)In [ ]:
alice = Person("Alice")
bob = Person("Bob")
alice.say_hello_to(bob)In [ ]:
bob # using the repr functionalityIn [ ]:
from scipy.integrate import simps
class Scientist(Person):
def integrate(self, x, y):
return simps(y, x=x)In [ ]:
alice = Scientist("Alice")
alice.integrate([1,2,3], [4,5,6])In [ ]:
aliceIn [ ]:
bob = Person("Bob")
alice.say_hello_to(bob)In [ ]:
eve = Scientist("Eve")
alice.say_hello_to(eve)In [ ]:
p = Person('Tom')
p.say_hello()In [ ]:
p.name = 'Alice'
p.say_hello()In [ ]:
p.age = 97
p.name
p.ageIn [ ]:
class Point(object):
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = zIn [ ]:
pt = Point(1, 2, 3)
pt.yIn [ ]:
def find_separation(p1, p2):
return np.sqrt((p1.x - p2.x)**2 + (p1.y - p2.y)**2 + (p1.z - p2.z)**2)In [ ]:
def find_separation(x1, y1, z1, x2, y2, z2):
return np.sqrt((x1 - x2)**2 + (y1 - y2)**2 + (z1 - z2)**2)In [ ]:
# your solution here