The same object in the memory is referred by both
list_a
and list_x
Code
PYTHON
Output
Code
PYTHON
Output
Default args are evaluated only once when the function is defined, not each time the function is called.
Code
PYTHON
Output
Built-in functions
Built-in functions are readily available for reuse.
We are already using functions which are pre-defined in Python
- print()
- int()
- str()
- len()
Finding Minimum
min()
returns the smallest item in a sequence or smallest of two or more arguments.PYTHON
Example - 1
Code
PYTHON
Output
Example - 2
Code
PYTHON
Output
Minimum of Strings
min(str_1, str_2)
Strings are compared character by character using unicode values.
- P - 80(unicode)
J - 74(unicode)
Code
PYTHON
Output
Finding Maximum
max()
returns the largest item in a sequence or largest of two or more arguments.PYTHON
Example - 1
Code
PYTHON
Ouput
Example - 2
Code
PYTHON
Output
Finding Sum
sum(sequence)
returns sum of items in a sequence.Code
PYTHON
Output
Ordering List Items
sorted(sequence)
returns a new sequence with all the items in the given sequence ordered in increasing order.Code
PYTHON
Output
Ordering List Items - Reverse
sorted(sequence, reverse=True)
returns a new sequence with all the items in the given sequence ordered in decreasing order.Code
PYTHON