user8730776
user8730776

Reputation:

Creating instance of class without using class name in Python

Is it possible to create a class that can be instantiated without using the actual name of said class? For instance when we make a string, we are instantiating the 'String' class but we aren't using the word 'String' while doing so. e.g.

example = "Hello, World!"

If it is possible to create such a class, how would one go about doing so?

Upvotes: 0

Views: 878

Answers (1)

Fergus
Fergus

Reputation: 471

There is no way to instantiate an object without defining what it is you are attempting to build. A class (object) is simply a representation of a program stored in memory. Similar to a variable, the object name defines where that object is stored in memory and how to access that data from memory. You can alias the object within your current program by simply assigning a new variable name to instantiate the object, but you do have to call the object out in order to work with it.

Upvotes: 1

Related Questions