Output, Input and Inspection
print, input, len, type, help, repr, id, hash, dir and friends.
This is an overview — pick a sub-topic below.
Sub-topics (11)
print()
Writes values to the screen (or a file), separated by sep and ended by end.
input()
Reads one line from the keyboard as a string (without the newline).
len()
Returns the number of items in a string, list, tuple, dict, set or any object with __len__.
type()
Returns an object's type; with three arguments it creates a new class dynamically.
help()
Shows the documentation of a module, function or class in the interactive shell.
repr()
Returns an unambiguous, developer-friendly string — what the REPL shows.
format()
Formats a single value using the same mini-language as f-strings.
hash()
Returns the integer hash used by dicts and sets; only immutable (hashable) objects have one.
id()
Returns a unique integer identity for an object during its lifetime (its memory address in CPython).
dir()
Lists the attributes and methods of an object (or the names in the current scope).
vars(), globals() and locals()
Return the namespace dictionaries of an object, the module, or the current function.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.