Oggetto Python ()

La funzione object () restituisce un oggetto senza caratteristiche che è una base per tutte le classi.

La sintassi di object()è:

 o = oggetto ()

Object () Parametri

La object()funzione non accetta alcun parametro.

Valore restituito da object ()

La object()funzione restituisce un oggetto senza caratteristiche.

Esempio: come funziona object ()?

 test = object() print(type(test)) print(dir(test))

Produzione

 ('__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init__', '__init__' __le__ ',' __lt__ ',' __ne__ ',' __new__ ',' __reduce__ ',' __reduce_ex__ ',' __repr__ ',' __setattr__ ',' __sizeof__ ',' __str__ ',' __subclasshook__ ') 

Qui viene creato un test dell'oggetto.

Nel programma abbiamo usato type () per ottenere il tipo di oggetto.

Allo stesso modo, abbiamo usato dir () per ottenere tutti gli attributi. Questi attributi (proprietà e metodi) sono comuni alle istanze di tutte le classi Python.

Articoli interessanti...