Die magische __bool__-Methode
»__bool__«
main.py
class C():
passc = C()
print( bool( c ))
print( 'A' if c else 'B' )
class C():
def __bool__( self ):
return False
passc = C()
print( bool( c ))
print( 'A' if c else 'B' )
- Protokoll
True
A
False
B
Die magische __bool__-Methode
(Die magische __bool__-Methode), Lektion, Seite 724750
https://www.purl.org/stefan_ram/pub/bool_methode_python
(Permalink) ist die kanonische URI dieser Seite.
Stefan Ram
main.py
class C():
passc = C()
print( bool( c ))
print( 'A' if c else 'B' )
class C():
def __bool__( self ):
return False
passc = C()
print( bool( c ))
print( 'A' if c else 'B' )
True
A
False
B
Seiteninformationen und Impressum | Mitteilungsformular | "ram@zedat.fu-berlin.de
" (ohne die Anführungszeichen) ist die Netzpostadresse von Stefan Ram. | Eine Verbindung zur Stefan-Ram-Startseite befindet
sich oben auf dieser Seite hinter dem Text "Stefan Ram".) |
Der Urheber dieses Textes ist Stefan Ram. Alle Rechte sind vorbehalten.
Diese Seite ist eine Veröffentlichung von Stefan Ram.
Schlüsselwörter zu dieser Seite/relevant keywords describing this page:
Stefan Ram Berlin slrprd slrprd stefanramberlin spellched stefanram724750 stefan_ram:724750
Die magische __bool__-Methode
Stefan Ram, Berlin, and, or, near, uni, online,
slrprd, slrprdqxx, slrprddoc, slrprd724750, slrprddef724750, PbclevtugFgrsnaEnz
Erklärung, Beschreibung, Info, Information, Hinweis,
Der Urheber dieses Textes ist Stefan Ram. Alle Rechte sind vorbehalten.
Diese Seite ist eine Veröffentlichung von Stefan Ram.
https://www.purl.org/stefan_ram/pub/bool_methode_python