#### Numeric Functions

abs ( ) : Returns an absolute value of a number. The argument may be an integer or a floating point number.

Synatx:

`abs (x)`

Example:

`x=20y=-23.2print('x = ', abs(x))print('y = ', abs(y))`

Output:

x = 20

y = 23.2

ord ( ) : Returns the ASCII value for the given Unicode character. This function is inverse of chr() function.

Sytanx:

`ord (c)`

Example:

`c= 'a'd= 'A'print ('c = ',ord (c))print ('A = ',ord (d))`

Output:

c = 97

A = 65

chr ( ) : Returns the Unicode character for the given ASCII value. This function is inverse of ord() function.

Syntax:

`chr (i)`

Example:

`c=65d=43print (chr (c))prin t(chr (d))`

Output:

A

+

bin ( ) : Returns a binary string prefixed with “0b” for the given integer number.

Note: format () can also be used instead of this function.

Syntax:

`bin (i)`

Example:

`x=15y=101print ('15 in binary : ',bin (x))print ('101 in binary : ',bin (y))`

Output:

15 in binary : 0b1111

101 in binary : 0b1100101

min ( ) : Returns the minimum value in a list.

Syntax:

min (list)

Example:

`MyList = [21,76,98,23]print ('Minimum of MyList :', min(MyList))`

Output:

Minimum of MyList : 21

Qus: What is a function? How is it useful?

A function is a named block in a program which has some certain working. Whenever you call this it performs all its working. It reduces the complexity and reduces the labour of writing same code again and again.

Qus: What is an argument? Give an example of one.

Ans : An argument is the requirement of a function to perform its working. For ex- pow(x,y), here x and y are the arguments which are required to pass to pow() for its working.

Qus. What is a string slice? How is it useful?

Ans: String Slice is a part of a string containing some contiguous characters from the string. It is accessed from the string by providing a range in ―[ ]‖ brackets i.e. S [n:m]. Python returns all the characters at indices n, n+1, n+2 . . . m-1 e.g. 'Barabanki'.[4:7] will return 'ban'.

Qus. Which functions would you chose to use to remove leading and trailing white spaces from a given string?

Ans: Python String strip() function will remove leading and trailing white spaces. If you want to remove only leading or trailing spaces, use lstrip() or rstrip() function instead.

Qus. Suggest appropriate functions for the following tasks –

(a) To check whether the string contains digits.

(b) To find the occurrence a string within another string.

(c) To convert the first letter of a string to upper case.

(d) To convert all the letters of a string to upper case.

(f) To check whether all the letters of the string are in capital letters.

(g) to remove all the white spaces from the beginning of a string.

Ans.  (a) isalnum() (b) find() (c) capitalize()   (d) upper() (f) isupper() (g) lstrip()

#### Programs

python program input string and prints its characters in different lines two characters per line

python to print the number of occurrences of a sub string into a line

python program to check the given string is palindrome or not

Python program to convert decimal into other number systems

python program that inputs a string and then prints it equal to number of times its length

Python program to illustrate the global variable

python program to create a function to calculate factorial value

Python program to find the sum of factorial upto n terms using function

python program to create a function for reverse the number

Python program to check number is Palindrome or not using function

Python program to create a function for calculating sum of digit

Python program to create recursive function to find factorial