Attribute

Attribute:
You can assign values to an instance using dot notation:

>>> blank.x=3.0
>>>blank.y=4.0
This syntax is similar to the syntax for selecting a variable from a module,such as math.pi or string.whitespace.In this  case,though,we are assigning values to named elements of an object.These elements are called attributes.
Example:
>>>print blank.y
4.0
>>>x=blank.x
>>>print x
3.0

1.Display the points of rectangle:

>>>print'(%g,%g)'%(blank.x,blank.y)
(3.0,4.0)
>>>distance=math.sqrt(blank.x**2+blank.y**2)
>>>print distance
5.0
def print_point(p):
print'(%g,%g)'%(p.x,p.y)
>>>print_point(blank)
(3.0,4.0)
Translate »