SyntaxStudy
Sign Up
Home Python Reference

Python Reference

22 entries — click any item for full details and examples

Built-in Functions

Name Description
print() Prints objects to the text stream, separated by sep and followed by end.
len() Returns the number of items in a container (string, list, tuple, dict, set, etc.).
range() Returns an immutable sequence of numbers. Commonly used in for loops.
type() / isinstance() type() returns the type of an object; isinstance() checks if an object is an instance of a class.
enumerate() Adds a counter to an iterable, returning (index, value) pairs. Avoids manual counter variables.
zip() Aggregates elements from multiple iterables into tuples. Stops at the shortest iterable.
map() / filter() map() applies a function to each item; filter() keeps items where the function returns True.
sorted() / reversed() sorted() returns a new sorted list; reversed() returns a reverse iterator. Neither modifies the original.
open() / with statement Opens a file and returns a file object. Always use with statement to ensure the file is properly closed.
int() / float() / str() Convert values between types. Raises ValueError if conversion is not possible.

List Methods

Name Description
append() / extend() / insert() append() adds one item to the end; extend() adds all items from an iterable; insert() adds at a specific index.
pop() / remove() / clear() pop() removes and returns item at index; remove() removes first occurrence of value; clear() empties the list.
sort() / reverse() sort() sorts the list in place; reverse() reverses it in place. Both modify the original list.
List Comprehensions A concise way to create lists. More readable and often faster than equivalent for loops.

String Methods

Name Description
split() / join() split() breaks a string into a list; join() concatenates an iterable into a string with a separator.
strip() / lstrip() / rstrip() Remove leading and trailing whitespace (or specified characters) from a string.
replace() Returns a copy of the string with all (or count) occurrences of old replaced by new.
f-strings Python 3.6 Formatted string literals — embed expressions inside string constants using curly braces.

Dictionary Methods

Name Description
dict.get() / dict.setdefault() get() returns value for key or default if missing; setdefault() sets and returns default if key is absent.
dict.keys() / values() / items() Return view objects of a dictionary's keys, values, or key-value pairs respectively.
dict.update() / dict.pop() update() merges another dict in place; pop() removes and returns the value for a key.
Dictionary Comprehensions Concise syntax for creating dictionaries from iterables or transforming existing dictionaries.