Page 207 - Computer Science V2.0 Class 11
P. 207
However, it is perfectly fine to interpret a string object as shown below:
>>> eval('"hello"')
'hello'
What will be displayed on executing the statement?
print(eval('15+10')*5)
What will be displayed on executing the statement?
print('15+10'*5)
max()
The max() function returns the largest value from the sequence of values provided as the input argument. The syntax
of the function is:
max(<sequence>) or max(<val1,val2,...,valn>)
For instance, the following function calls print maximum of the numeric values and largest string from the values
provided as the input:
>>> max(2,0,-4,19.0,36,8)
36
>>> max('Arushi','Muskan','Sameer','Ayana')
'Sameer'
Strings are compared from left to right, examining each character one by one, using their ASCII codes, which are also
known as ASCII values. Note that the values passed to max function must be compatible for comparison. For example,
a numeric value cannot be compared against a string value as shown below:
What value does max(-20, -30, -40) yield?
>>> max(23, 'hello')
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
max(23, 'hello')
TypeError: '>' not supported between instances of 'str' and 'int'
min()
The min() function returns the smallest value from the sequence of values provided as the argument. The syntax of
the function is :
min(<sequence>) or min(<val1,val2,...,valn>)
For instance, the following function calls print minimum of the numeric values and smallest string from the values
provided as the input:
>>> min(2,0,-4,19.0,36,8)
-4
>>> min('Arushi','Muskan','Sameer','Ayana')
'Arushi'
sum()
The sum() function returns sum of all numeric values in the given input sequence. Optional input num2, when
provided, is added to the sum of elements of the sequence. The syntax of the function is :
sum(<sequence [,num2]>)
Introduction to Functions 193

