Python Tutorial ( PDFDrive )
abs(100.12) : 100.12abs(119L) : 119ceil(x) Description The method ceil() returns ceiling value of x - the smallest integer not less than x.Syntax Following is the syntax for ceil() method:import mathmath.ceil( x )Note: This function is not accessible directly, so we need to import math module and then we need to call thisfunction using math static object.Parameters • x -- This is a numeric expression.Return Value This method returns smallest integer not less than x.Example The following example shows the usage of ceil() method.#!/usr/bin/pythonimport math # This will import math moduleprint "math.ceil(-45.17) : ", math.ceil(-45.17)print "math.ceil(100.12) : ", math.ceil(100.12)print "math.ceil(100.72) : ", math.ceil(100.72)print "math.ceil(119L) : ", math.ceil(119L)print "math.ceil(math.pi) : ", math.ceil(math.pi)Let us compile and run the above program, this will produce the following result:math.ceil(-45.17) : -45.0math.ceil(100.12) : 101.0math.ceil(100.72) : 101.0math.ceil(119L) : 119.0math.ceil(math.pi) : 4.0cmp(x, y) Description The method cmp() returns the sign of the difference of two numbers : -1 if x < y, 0 if x == y, or 1 if x > y .TUTORIALS POINT Simply Easy Learning
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 > yExample The following example shows the usage of cmp() method.#!/usr/bin/pythonprint "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) : -1cmp(180, 100) : 1cmp(-80, 100) : -1cmp(80, -100) : 1exp(x) Description The method exp() returns returns exponential of x: e x .Syntax Following is the syntax for exp() method:import mathmath.exp( x )Note: This function is not accessible directly, so we need to import math module and then we need to call thisfunction using math static object.Parameters • x -- This is a numeric expression.TUTORIALS POINT Simply Easy Learning
- Page 45 and 46: • To use this installer python-XY
- Page 47 and 48: -c cmd run Python script sent in as
- Page 49 and 50: This will produce the following res
- Page 51 and 52: file_name = raw_input("Enter filena
- Page 53 and 54: $ python -husage: python [option] .
- Page 55 and 56: print 'Input file is "', inputfilep
- Page 57 and 58: Here, an integer object is created
- Page 59 and 60: Python Lists: Lists are the most v
- Page 61 and 62: FunctionDescriptionint(x [,base])Co
- Page 63 and 64: CHAPTER5Python Basic OperatorsWhat
- Page 65 and 66: Line 4 - Value of c is 2Line 5 - Va
- Page 67 and 68: Line 5 - a is greater than bLine 6
- Page 69 and 70: | Binary OR Operator copies a bit i
- Page 71 and 72: else:print "Line 3 - a and b are tr
- Page 73 and 74: if ( id(a) == id(b) ):print "Line 2
- Page 75 and 76: When you execute the above program,
- Page 77 and 78: if statementsif...else statementsne
- Page 79 and 80: Example: #!/usr/bin/pythonvar1 = 10
- Page 81 and 82: else:print "Could not find true exp
- Page 83 and 84: Loop Typewhile loopfor loopDescript
- Page 85 and 86: num = raw_input("Enter a number :")
- Page 87 and 88: Good bye!Iterating by Sequence I
- Page 89 and 90: 11 is prime13 is prime17 is prime19
- Page 91 and 92: continue statement The continue st
- Page 93 and 94: CHAPTER8Python NumbersNumber data t
- Page 95: max(x1, x2,...)min(x1, x2,...)modf(
- Page 99 and 100: import math# This will import math
- Page 101 and 102: import mathmath.log10( x )Note: Thi
- Page 103 and 104: modf(x) Description The method modf
- Page 105 and 106: round( x [, n] )Parameters • x --
- Page 107 and 108: Return Value This method returns a
- Page 109 and 110: seed([x]) Description The method se
- Page 111 and 112: Syntax Following is the syntax for
- Page 113 and 114: asin(x)Note: This function is not a
- Page 115 and 116: print "atan2(-10,10) : ", math.atan
- Page 117 and 118: Note: This function is not accessib
- Page 119 and 120: import mathprint "degrees(3) : ", m
- Page 121 and 122: CHAPTER9Python StringsStrings are a
- Page 123 and 124: + Concatenation - Adds values on ei
- Page 125 and 126: TAB ( \t ) and they will show up th
- Page 127 and 128: 14151617181920212223242526272829303
- Page 129 and 130: str = "this is string example....wo
- Page 131 and 132: Return Value This method returns a
- Page 133 and 134: Description The method expandtabs()
- Page 135 and 136: Traceback (most recent call last):F
- Page 137 and 138: Let us compile and run the above pr
- Page 139 and 140: str = "This is string example....wo
- Page 141 and 142: str = "-";seq = ("a", "b", "c"); #
- Page 143 and 144: lstrip() Description The method lst
- Page 145 and 146: Max character: xmin(str) Descriptio
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