class Point:
""" Point class represents and manipulates x,y coords. """
def __init__(self):
""" Create a new point at the origin """
self.x = 0
self.y = 0
p = Point() # Instantiate an object of type Point
q = Point() # Make a second point
print(p.x, p.y, q.x, q.y) # Each point object has its own x and y
>>> p.x = 3
>>> p.y = 4
>>> print(p.y)
4
>>> x = p.x
>>> print(x)
3
As for stack, it is a kind of built-in list of python, and we need to remember the basic methods that are:
(1):__init__ Initialize a new empty stack.
(2): push add a new item to the stack.
(3) : pop Remove and return an item from the stack.
(4) : is_empty Check whether the stack is empty.
self.x = 0
self.y = 0
p = Point() # Instantiate an object of type Point
q = Point() # Make a second point
print(p.x, p.y, q.x, q.y) # Each point object has its own x and y
>>> p.x = 3
>>> p.y = 4
>>> print(p.y)
4
>>> x = p.x
>>> print(x)
3
As for stack, it is a kind of built-in list of python, and we need to remember the basic methods that are:
(1):__init__ Initialize a new empty stack.
(2): push add a new item to the stack.
(3) : pop Remove and return an item from the stack.
(4) : is_empty Check whether the stack is empty.
>>> stack = [3,4,5]
>>> stack.append(6)
>>> stack.append(7)
>>> stack
{3,4,5,6,7]
>>> stack.pop()
7
>>>stack
[3,4,5,6]
>>> stack.pop()
6
>>>stack.pop()
5
>>> stack
[3,4]
No comments:
Post a Comment