Python Functions for datatype
Python Functions for datatype
No
1 list.append(item) Adds an item to the end of the list. [1, 2, 3].append(4) → [1, 2,
3, 4]
1 dict.get(key) Returns the value for the specified key. {'a': 1}.get('a') → 1
6 dict.pop(key) Removes and returns the value for the {'a': 1}.pop('a') → 1
specified key.
2 set.update(iterable Adds all items from an iterable to the {1, 2}.update([3, 4]) →
set.
) {1, 2, 3, 4}
3 set.remove(item) Removes an item from the set. Raises {1, 2}.remove(2) → {1}
KeyError if item not found.
4 set.discard(item) Removes an item from the set if present, {1, 2}.discard(2) → {1}
does nothing if not found.
6 set.clear() Removes all items from the set. {1, 2, 3}.clear() → set()
3 range.step Returns the step value of the range. range(1, 10, 2).step → 2
Additional Methods for String (str) Data Type
8 set.union(*others) Returns a new set with all {1, 2}.union({3, 4}) → {1, 2,
elements from the set and all
other sets.
3, 4}