A class is a kind of definition. It allows us to describe a certain kind of object, and then later we can use that definition to create one, two, or even dozens of copies of that object, called instances, using the class definition.
We've already started diving into the realm of custom classes with our World
class. We put the definition for that class into the same file we were running in the Windows command prompt, so we didn't need to import it to gain access to it. If it were in another file, for example WorldClass.py
, we would need to use an import
statement to gain access to it. That import statement would look like this:
from WorldClass import World
The from
part of the statement tells Python what file to look in to find the definition of the World
class we are telling it to import. For this to work, the file we're running and the file we're importing should be in the same directory. If they aren't, we would need to include a relative path from the file we're...