You can also test if one spatial object contains another, such as a point in a polygon or a city in a state using the contains function. This can be used to determine if a location is in a postal code, province, or congressional district. The within function is the inverse and determines if the object is within another object:
#import polygon class
from shapely.geometry import Polygon
#create a square polygon
polysquare = Polygon([(0,0),(0,2),(2,2),(2,0),(0,0)])
#test if polygon contains the point
print(polysquare.contains(Point(1,1)))
#test if point is within the polygon
print(Point(1,1).within(polysquare))
#test if other point is within the polygon
print(Point(5,7).within(polysquare))