Available under Creative Commons-NonCommercial-ShareAlike 4.0 International License.
Functions can return instances. For example, find_center takes a Rectangle as an argument and returns a Point that contains the coordinates of the center of the Rectangle:
def find_center(rect):p = Point()p.x = rect.corner.x + rect.width/2.0p.y = rect.corner.y + rect.height/2.0return p
Here is an example that passes box as an argument and assigns the resulting Point to center:
>>> center = find_center(box)>>> print_point(center)(50.0, 100.0)
- 瀏覽次數:1401