You are trying to create College() objects inside the class College, but outside any function in that class. That is what's causing the error.
If you unindent the part after __init__, it will work, like so:
def education():
class College:
type = "University"
def __init__(self, name, location):
self.name = name
self.location = location
iet = College("IET", "Kanpur")
jim = College("JIM", "Lucknow")
edu1 = print("IET is a {}".format(iet.__class__.type))
edu2 = print("JIM is also a {}".format(jim.__class__.type))
loc1 = print("{} is located in {}".format(iet.name, iet.location))
loc2 = print("{} is located in {}".format(jim.name, jim.location))
return edu1, edu2, loc1, loc2
education()
However, I would advise to define the class College before the function, like so:
class College:
type = "University"
def __init__(self, name, location):
self.name = name
self.location = location
def education():
iet = College("IET", "Kanpur")
jim = College("JIM", "Lucknow")
edu1 = print("IET is a {}".format(iet.__class__.type))
edu2 = print("JIM is also a {}".format(jim.__class__.type))
loc1 = print("{} is located in {}".format(iet.name, iet.location))
loc2 = print("{} is located in {}".format(jim.name, jim.location))
return edu1, edu2, loc1, loc2
education()
Edit: You're declaring type in class College, thereby hiding Python's type. It is not advised to use names for variables that are default keywords in Python, such as list, dict, type.
Edit2: As Ishwar pointed out, you're storing the return from print statements in loc1 and loc2. print() always returns None, so there is no use in storing it in variables. If you wanted to store the formatted strings, store those in variables and then print those variables.