pythonstdlibtip's profile picture. Python built-in functions and modules tips, approximately one tip per week day. Shamelessly copied from http://docs.python.org by @dmlvianna.

Python StdLib Tip

@pythonstdlibtip

Python built-in functions and modules tips, approximately one tip per week day. Shamelessly copied from http://docs.python.org by @dmlvianna.

Ghim

filter(function, iterable) Construct a list from those elements of iterable for which function returns true.


len(s) Return the length (number of items) of an object. The argument may be a sequence (string, tuple or list) or a mapping (dictionary).


iter(o[, x]) Return an iterator object. o must support iteration or sequencing. If x given, o must be callable and iteration will stop at x.


issubclass(class, classinfo) Return true if class is a subclass of classinfo. classinfo may be a tuple of class objects to be checked.


isinstance(object, class) Return true if the object is an instance of the class, or of a (direct, indirect or virtual) subclass thereof.


int(x) Convert a number or string x to an integer, or return 0 if no args. If x is floating point, the conversion truncates towards zero.


input([prompt]) Equivalent to eval(raw_input(prompt)). If readline is loaded, it provides elaborate line editing and history features.


id(object) This is an integer which is guaranteed to be unique and constant for this object during its lifetime.


hex(x) Convert an integer number (of any size) to a lowercase hexadecimal string prefixed with “0x”.


help([object]) Invoke the built-in help system. If no argument is given, the interactive help system starts on the interpreter console.


hash(object) Return the hash value of the object (if it has one). Hash values are integers, and are used to quickly compare dictionary keys.


hasattr(object, string) The result is True if the string is the name of one of the object’s attributes, False if not.


globals() Return a dictionary representing the current global symbol table. This is always the dictionary of the current module.


getattr(object, name[, default]) Return the value of the named attribute of object. If it does not exist, default is returned if provided.


frozenset([iterable]) Return a new frozenset object. frozenset is a built-in class. frozenset are like set objects, but are immutable.


format(value[, format_spec]) Convert a value to a “formatted” representation. format_spec mini-language: tinyurl.com/mtpo4l5


float([x]) Convert a string or a number to floating point. Strings can be embedded in whitespace. Argument may also be [+|-]nan or [+|-]inf.


file() Constructor function for the file type. Arguments are the same as for open(). Use open() to open files, use file() for type testing.


execfile(filename[, globals[, locals]]) This function is similar to the exec statement, but parses a file instead of a string.


eval(expression[, globals[, locals]]) Evaluates a string or code object as a Python expression using current or supplied namespaces.


Loading...

Something went wrong.


Something went wrong.