28.10.2021 Views

Python Tutorial ( PDFDrive )

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Syntax

Following is the syntax for cmp() method:

cmp( x, y )

Parameters

• x -- This is a numeric expression.

• y -- This is also a numeric expression.

Return Value

This method returns -1 if x < y, returns 0 if x == y and 1 if x > y

Example

The following example shows the usage of cmp() method.

#!/usr/bin/python

print "cmp(80, 100) : ", cmp(80, 100)

print "cmp(180, 100) : ", cmp(180, 100)

print "cmp(-80, 100) : ", cmp(-80, 100)

print "cmp(80, -100) : ", cmp(80, -100)

Let us compile and run the above program, this will produce the following result:

cmp(80, 100) : -1

cmp(180, 100) : 1

cmp(-80, 100) : -1

cmp(80, -100) : 1

exp(x)

Description

The method exp() returns returns exponential of x: e x .

Syntax

Following is the syntax for exp() method:

import math

math.exp( x )

Note: This function is not accessible directly, so we need to import math module and then we need to call this

function using math static object.

Parameters

• x -- This is a numeric expression.

TUTORIALS POINT

Simply Easy Learning

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!