Karteikarten
python strings and representations
Karten in diesem Stapel (15)
- 1what are the 2 string representations in python?str(obj) and repr(obj)
- 2how do you set str(obj) in your class__str__(self)
- 3how do you set repr(obj) for your class?__repr__(self)
- 4which should you always implement for your classes__repr__(self)
- 5who is __repr__ for?its primarily for developers
- 6what should you include in __repr__ ?include type
make it precise and unambiguous - 7if there is no __str__ what happens?__str__ by default falls back to use __repr__
- 8which representation does print() use?print uses str
- 9what does format use?format uses __format__(self,f)
- 10what module allows for drop in replacement for repr?import reprlib
from reprlib import Repr
reprlib.repr(obj) - 11what does reprlib give you?it limits output size for large collectoins
- 12what function takes and returns a unicode string?s=ascii(string)
- 13how do you get an integer codepoint for a characterthe ord() function takes in single char unicode string and returns integer codepoint for that character
i=ord(c) - 14how do you get a single character from an integer code point?chr() takes in an integer codepoint and returns the single character string
- 15which 2 character functions are inverses of each other?ord() and chr() are inverses of each other
Informationen
- Beschreibung
- python (beyond basics python flashcards) Karteikarten am python strings and representations, erstellt von Andrew Sperazza am 10/01/2017.
- Erstellt von
- Andrew Sperazza
- Aufrufe
- 5
- Bewertung