0

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?

2
  • Python recognizes some built-in data types (eg int,string) in python standard library . If you want such a behaviour, you are looking to extend the built-in types. Commented Nov 12, 2017 at 16:14
  • Extending a built-in type doesn't allow you to co-opt the existing literals. They are hard-coded to produce a specific class. Commented Nov 12, 2017 at 16:50

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.