Python Tutorial ( PDFDrive )
aList = [123, 'xyz', 'zara', 'abc', 123];bList = [2009, 'manni'];aList.extend(bList)print "Extended List : ", aList ;Let us compile and run the above program, this will produce the following result:Extended List : [123, 'xyz', 'zara', 'abc', 123, 2009, 'manni']list.index(obj) Description The method index() returns the lowest index in list that obj appears.SyntaxFollowing is the syntax for index() method:list.index(obj)Parameters• obj -- This is the object to be find out.Return Value This method returns index of the found object otherwise raise an exception indicating that value does not find.ExampleThe following example shows the usage of index() method.#!/usr/bin/pythonaList = [123, 'xyz', 'zara', 'abc'];print "Index for xyz : ", aList.index( 'xyz' ) ;print "Index for zara : ", aList.index( 'zara' ) ;Let us compile and run the above program, this will produce the following result:Index for xyz : 1Index for xxx : 2list.insert(index, obj) Description The method insert() inserts object obj into list at offset index.Syntax Following is the syntax for insert() method:TUTORIALS POINT Simply Easy Learning
list.insert(index, obj)Parameters • index -- This is the Index where the object obj need to be inserted.• obj -- This is the Object to be inserted into the given list.Return Value This method does not return any value but it inserts the given element at the given index.Example The following example shows the usage of insert() method.#!/usr/bin/pythonaList = [123, 'xyz', 'zara', 'abc']aList.insert( 3, 2009)print "Final List : ", aListLet us compile and run the above program, this will produce the following result:Final List : [123, 'xyz', 'zara', 2009, 'abc']list.pop(obj=list[-‐1]) Description The method pop() removes and returns last object or obj from the list.Syntax Following is the syntax for pop() method:list.pop(obj=list[-1])Parameters • obj -- This is an optional parameter, index of the object to be removed from the list.Return Value This method returns the removed object from the list.Example The following example shows the usage of pop() method.#!/usr/bin/pythonaList = [123, 'xyz', 'zara', 'abc']print "A List : ", aList.pop()TUTORIALS POINT Simply Easy Learning
- 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
- 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: Return Value If elements are of th
- Page 169 and 170: Syntax Following is the syntax for
- Page 171 and 172: CHAPTER11Python TuplesAtuple is a s
- Page 173 and 174: len((1, 2, 3)) 3 Length(1, 2, 3) +
- Page 175 and 176: -11-1len(tuple) Description The met
- Page 177 and 178: min value element : 200tuple(seq) D
- Page 179 and 180: #!/usr/bin/pythondict = {'Name': 'Z
- Page 181 and 182: 34str(dict)Produces a printable str
- Page 183 and 184: type(variable) Description The meth
- Page 185 and 186: Syntax Following is the syntax for
- Page 187 and 188: Syntax Following is the syntax for
- Page 189 and 190: Return Value This method does not
- Page 191 and 192: CHAPTER13Python Date & TimeApython
- Page 193 and 194: #!/usr/bin/pythonimport time;localt
- Page 195 and 196: import timeprint "time.altzone %d "
- Page 197 and 198: Parameters • sec -- These are the
- Page 199 and 200: Example The following example shows
- Page 201 and 202: • %w - day of the week as a decim
- Page 203 and 204: time.time( ) Description The metho
- Page 205 and 206: 2time.tznameAttribute time.tzname i
- Page 207 and 208: CHAPTER14Python FunctionAfunction i
- Page 209 and 210: #!/usr/bin/python# Function definit
- Page 211 and 212: return;# Now you can call printinfo
- Page 213 and 214: Inside the function : 30Outside the
- Page 215 and 216: A module is loaded only once, regar
aList = [123, 'xyz', 'zara', 'abc', 123];
bList = [2009, 'manni'];
aList.extend(bList)
print "Extended List : ", aList ;
Let us compile and run the above program, this will produce the following result:
Extended List : [123, 'xyz', 'zara', 'abc', 123, 2009, 'manni']
list.index(obj)
Description
The method index() returns the lowest index in list that obj appears.
Syntax
Following is the syntax for index() method:
list.index(obj)
Parameters
• obj -- This is the object to be find out.
Return Value
This method returns index of the found object otherwise raise an exception indicating that value does not find.
Example
The following example shows the usage of index() method.
#!/usr/bin/python
aList = [123, 'xyz', 'zara', 'abc'];
print "Index for xyz : ", aList.index( 'xyz' ) ;
print "Index for zara : ", aList.index( 'zara' ) ;
Let us compile and run the above program, this will produce the following result:
Index for xyz : 1
Index for xxx : 2
list.insert(index, obj)
Description
The method insert() inserts object obj into list at offset index.
Syntax
Following is the syntax for insert() method:
TUTORIALS POINT
Simply Easy Learning