Python Tutorial ( PDFDrive )
print "radians(3) : ", math.radians(3)print "radians(-3) : ", math.radians(-3)print "radians(0) : ", math.radians(0)print "radians(math.pi) : ", math.radians(math.pi)print "radians(math.pi/2) : ", math.radians(math.pi/2)print "radians(math.pi/4) : ", math.radians(math.pi/4)Let us compile and run the above program, this will produce the following result:radians(3) : 0.0523598775598radians(-3) : -0.0523598775598radians(0) : 0.0radians(math.pi) : 0.0548311355616radians(math.pi/2) : 0.0274155677808radians(math.pi/4) : 0.0137077838904Mathematical Constants: The module also defines two mathematical constants:ConstantsDescriptionPiThe mathematical constant pi.E The mathematical constant e.TUTORIALS POINT Simply Easy Learning
CHAPTER9Python StringsStrings are amongst the most popular types in Python. We can create them simply by enclosing charactersin quotes. Python treats single quotes the same as double quotes.Creating strings is as simple as assigning a value to a variable. For example:var1 = 'Hello World!'var2 = "Python Programming"Accessing Values in Strings: Python does not support a character type; these are treated as strings of length one, thus also considered asubstring.To access substrings, use the square brackets for slicing along with the index or indices to obtain your substring.Following is a simple example:#!/usr/bin/pythonvar1 = 'Hello World!'var2 = "Python Programming"print "var1[0]: ", var1[0]print "var2[1:5]: ", var2[1:5]When the above code is executed, it produces the following result:var1[0]: Hvar2[1:5]: ythoUpdating Strings: You can "update" an existing string by (re)assigning a variable to another string. The new value can be related toits previous value or to a completely different string altogether. Following is a simple example:#!/usr/bin/pythonvar1 = 'Hello World!'TUTORIALS POINT Simply Easy Learning
- 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 and 96: max(x1, x2,...)min(x1, x2,...)modf(
- Page 97 and 98: Syntax Following is the syntax for
- 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: import mathprint "degrees(3) : ", m
- 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
- Page 147 and 148: str = "this is really a string exam
- Page 149 and 150: Parameters • chars -- You can sup
- Page 151 and 152: Parameters• str -- This is the st
- Page 153 and 154: Parameters • NAReturn Value This
- Page 155 and 156: Example The following example shows
- Page 157 and 158: CHAPTER10Python ListsThe most basic
- Page 159 and 160: Python Expression Results Descripti
- Page 161 and 162: Syntax Following is the syntax for
- Page 163 and 164: list( seq )Parameters • seq -- Th
- Page 165 and 166: Return Value If elements are of th
- Page 167 and 168: list.insert(index, obj)Parameters
- Page 169 and 170: Syntax Following is the syntax for
CHAPTER
9
Python Strings
Strings are amongst the most popular types in Python. We can create them simply by enclosing characters
in quotes. Python treats single quotes the same as double quotes.
Creating strings is as simple as assigning a value to a variable. For example:
var1 = 'Hello World!'
var2 = "Python Programming"
Accessing Values in Strings:
Python does not support a character type; these are treated as strings of length one, thus also considered a
substring.
To access substrings, use the square brackets for slicing along with the index or indices to obtain your substring.
Following is a simple example:
#!/usr/bin/python
var1 = 'Hello World!'
var2 = "Python Programming"
print "var1[0]: ", var1[0]
print "var2[1:5]: ", var2[1:5]
When the above code is executed, it produces the following result:
var1[0]: H
var2[1:5]: ytho
Updating Strings:
You can "update" an existing string by (re)assigning a variable to another string. The new value can be related to
its previous value or to a completely different string altogether. Following is a simple example:
#!/usr/bin/python
var1 = 'Hello World!'
TUTORIALS POINT
Simply Easy Learning