<jupyter_start><jupyter_text>Create New Class:<jupyter_code>class Mars:
    """Mars is the fourth planet from the Sun and the second-smallest planet in the Solar System after Mercury"""
Mars<jupyter_output><empty_output><jupyter_text>The class object is like a factory for creating objects. To create a Mars, you call Mars as if itwere a function.<jupyter_code>blank = Mars()
blank
blank.x = 3.0
blank.y = 4.0
print(blank.x)
print(blank.y)<jupyter_output>3.0
4.0<jupyter_text>You can use dot notation as part of any expression. For example:<jupyter_code>'(%g, %g)' % (blank.x, blank.y)<jupyter_output><empty_output><jupyter_text>You can pass an instance as an argument in the usual way. For example:<jupyter_code>import math
distance = math.sqrt(blank.x**2 + blank.y**2)
distance
def print_point(p):
    print('(%g, %g)' % (p.x, p.y))
print_point(blank)
class PandoraBox:
    """Represents a rectangle.
    attributes: width, height, corner.
    """
   
box = PandoraBox()
box.width = 100
box.height = 200
box.corner = Mars()
box.corner.x = 0
box.corner.y = 0
def find_center(rect):
    p = Mars()
    p.x = rect.corner.x + rect.width/2
    p.y = rect.corner.y + rect.height/2
    return p
center = find_center(box)
print_point(center)
def grow_rectangle(rect, dwidth, dheight):
    rect.width += dwidth
    rect.height += dheight
box.width, box.height
grow_rectangle(box, 50, 100)
box.width, box.height<jupyter_output><empty_output><jupyter_text>Copying<jupyter_code>m1 = Mars()
m1.x = 3.0
m1.y = 4.0
import copy
m2 = copy.copy(m1)
print_point(m1)
print_point(m2)
m1 is m2
box2 = copy.copy(box)
box2 is box
box2.corner is box.corner<jupyter_output><empty_output><jupyter_text>This operation is called a shallowcopy because it copies the object and any references it contains, but not the embeddedobjects. Deep Copy<jupyter_code>box3 = copy.deepcopy(box)
box3 is box
box3.corner is box.corner<jupyter_output><empty_output><jupyter_text>Classes and functions<jupyter_code>class Time:
    """Represents the time of day.
    attributes: hour, minute, second
    """
time = Time()
time.hour = 11
time.minute = 59
time.second = 30<jupyter_output><empty_output><jupyter_text>Pure functions<jupyter_code>def add_time(t1, t2):
    sum = Time()
    sum.hour = t1.hour + t2.hour
    sum.minute = t1.minute + t2.minute
    sum.second = t1.second + t2.second
    return sum
def print_time(x):
    print('(%g, %g)' % (sum.x, p.y))
start = Time()
start.hour = 9
start.minute = 45
start.second = 0
duration = Time()
duration.hour = 1
duration.minute = 35
duration.second = 0
done = add_time(start, duration)
print_time(done)
def add_time(t1, t2):
    sum = Time()
    sum.hour = t1.hour + t2.hour
    sum.minute = t1.minute + t2.minute
    sum.second = t1.second + t2.second
    
    if sum.second >= 60:
        sum.second -= 60
        sum.minute += 1
    if sum.minute >= 60:
        sum.minute -= 60
        sum.hour += 1
    return sum<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12622673434856177, 'fraction_numerical': 0.028426395939086295, 'mean_word_length': 3.9932432432432434, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '600243', 'license': 'MIT', 'n_tokens_mistral': 1141, 'n_tokens_neox': 1088, 'n_words': 285, 'path': 'python/Classes.ipynb', 'repo_name': 'piszewc/python-deep-learning-data-science', 'size': '2955'}