Python 3.1.1+ (r311:74480, Nov 2 2009, 14:49:22) [GCC 4.4.1] on linux2 Type "copyright", "credits" or "license()" for more information. >>> aVar = "test" >>> aVar.capitalize() 'Test' >>> aVar.count("e") 1 >>> aVar.find("e") 1 >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> aVar = "this string has a \n second line" >>> >>> >>> print(aVar) this string has a second line >>> >>> aVar = "this is a slash \" SyntaxError: EOL while scanning string literal (, line 1) >>> >>> aVar = "this is a slash \ in the line" >>> >>> >>> aVar 'this is a slash \\ in the line' >>> >>> >>> aVar 'this is a slash \\ in the line' >>> print(aVar) this is a slash \ in the line >>> aVar = "temp \\ double slash" >>> >>> aVar 'temp \\ double slash' >>> print(aVar) temp \ double slash >>> >>> >>> >>> aVar = "testing \nothing" >>> >>> >>> aVar 'testing \nothing' >>> print(aVar) testing othing >>> aVar = "testing\\nothing" >>> >>> aVar 'testing\\nothing' >>> print(aVar) testing\nothing >>> >>> >>> aVar = r"Testing\nothing" >>> >>> aVar 'Testing\\nothing' >>> >>> >>> >>> "C:\Program Files\MyProgram\mp.exe" 'C:\\Program Files\\MyProgram\\mp.exe' >>> >>> >>> aVar = "c:\Network Drive\np.exe" SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: malformed \N character escape (, line 1) >>> >>> aVar = "c:\network Drive\np.exe" >>> >>> aVar 'c:\network Drive\np.exe' >>> print(aVar) c: etwork Drive p.exe >>> >>> >>> "C:\\network drive\\np.exe" 'C:\\network drive\\np.exe' >>> >>> >>> >>> >>> >>> >>> aVar = "this is a string" >>> >>> >>> type(aVar) >>> >>> aVar.capitalize() 'This is a string' >>> >>> >>> >>> >>> aVar 'this is a string' >>> >>> newValue = aVar.capitalize() >>> >>> >>> newValue 'This is a string' >>> >>> >>> >>> aVar = aVar.capitalize() >>> >>> >>> aVar 'This is a string' >>> >>> >>> >>> >>> aVar 'This is a string' >>> aVar.count("s") 3 >>> aVar.find("s") 3 >>> aVar.find("s", 4) 6 >>> aVar.find("s", 6) 6 >>> aVar.find("s", 7) 10 >>> >>> >>> >>> aVar.find("s ") 3 >>> aVar.find("s ",4) 6 >>> >>> aVar.find("string") 10 >>> >>> aVar 'This is a string' >>> aVar[10:] 'string' >>> >>> aVar.find("T") 0 >>> aVar.find("T",1) -1 >>> aVar 'This is a string' >>> aVar.find("test") -1 >>> aVar.find("this") -1 >>> >>> aVar.lower() 'this is a string' >>> >>> >>> aVar 'This is a string' >>> temp = aVar.lower() >>> >>> temp 'this is a string' >>> temp.find("this") 0 >>> >>> >>> >>> >>> aVar 'This is a string' >>> aVar.lower().find("this") 0 >>> >>> >>> >>> >>> aVar 'This is a string' >>> >>> >>> aVar.split() ['This', 'is', 'a', 'string'] >>> >>> >>> >>> >>> >>> >>> aVar = "456,234,5431,4312" >>> >>> aVar '456,234,5431,4312' >>> aVar.split(",") ['456', '234', '5431', '4312'] >>> >>> >>> >>> aVar '456,234,5431,4312' >>> >>> aVar.replace("456", "Jay") 'Jay,234,5431,4312' >>> >>> aVar '456,234,5431,4312' >>> >>> aVar = aVar.replace("456", "Jay") >>> >>> >>> aVar 'Jay,234,5431,4312' >>> >>> aVar 'Jay,234,5431,4312' >>> aVar.replace(456, "Jay") Traceback (most recent call last): File "", line 1, in aVar.replace(456, "Jay") TypeError: Can't convert 'int' object to str implicitly >>> aVar.replace(4, "Jay") Traceback (most recent call last): File "", line 1, in aVar.replace(4, "Jay") TypeError: Can't convert 'int' object to str implicitly >>> >>> >>> >>> >>> >>> aVar 'Jay,234,5431,4312' >>> >>> aVar[7] ',' >>> aVar[0:7] 'Jay,234' >>> aVar[8:] '5431,4312' >>> newStr = aVar[0:7] + "*" + aVar[8:] >>> >>> newStr 'Jay,234*5431,4312' >>> aVar = "456,456" >>> >>> aVar.replace("456", "Jay") 'Jay,Jay' >>> >>> >>> aVar.replace("456", "Jay",1) 'Jay,456' >>> >>> >>> aVar = " this string has spaces " >>> >>> aVar ' this string has spaces ' >>> >>> >>> aVar.strip() 'this string has spaces' >>> >>> >>> aVar.rstrip() ' this string has spaces' >>> aVar.lstrip() 'this string has spaces ' >>> >>> >>> aVar ' this string has spaces ' >>> aVar.replace(" ", "") 'thisstringhasspaces' >>> >>> >>> >>> >>> "a string %i has stuff" % 45 'a string 45 has stuff' >>> >>> >>> >>> >>> >>> >>> >>> >>> "a string {} has some stuff {} " 'a string {} has some stuff {} ' >>> >>> "a string {} has some stuff {} ".format(45, "Jay") 'a string 45 has some stuff Jay ' >>> >>> >>> aStr = "a string {} has some stuff {} " >>> >>> >>> >>> aStr.format(18, True) 'a string 18 has some stuff True ' >>> >>> >>> >>> aStr.format(18.1412341, 23.241432123) 'a string 18.1412341 has some stuff 23.241432123 ' >>> >>> >>> aStr = "a string {0} has some stuff {1} " >>> >>> aStr.format(10.5555, 5.8888) 'a string 10.5555 has some stuff 5.8888 ' >>> >>> aStr = "a string {0:.1f} has some stuff {1:.1} " >>> >>> aStr.format(10.5555, 10.8888) 'a string 10.6 has some stuff 1.0e+01 ' >>> >>> aStr = "reverse {1} and {0}" >>> >>> aStr.format(10, 500) 'reverse 500 and 10' >>> >>> >>> >>> >>> >>> >>> >>> num = 10 >>> >>> print("first part", num, "second part") first part 10 second part >>> >>> >>> "first part{}second part".format(10) 'first part10second part' >>> >>> >>> "The old school version %.3f" % 10.143241234123 'The old school version 10.143' >>> >>> >>> >>> >>> >>> >>> aString = "245,234,366,345,345" >>> >>> aString '245,234,366,345,345' >>> >>> >>> >>> aList = aString.split(',') >>> >>> aList ['245', '234', '366', '345', '345'] >>> >>> >>> aList[0] '245' >>> >>> >>> aList[1] '234' >>> aList[1] = "Jay" >>> >>> >>> >>> aList ['245', 'Jay', '366', '345', '345'] >>> >>> >>> aList[4] '345' >>> aList[4] = True >>> >>> >>> aList ['245', 'Jay', '366', '345', True] >>> aList[3] = 10.555 >>> >>> aList ['245', 'Jay', '366', 10.555, True] >>> aList[1] = 5 >>> >>> aList ['245', 5, '366', 10.555, True] >>> >>> >>> >>> >>> for item in aList: print(item) 245 5 366 10.555 True >>> >>> >>> for item in aList: print(item, type(item) ) 245 5 366 10.555 True >>> >>> >>> aList ['245', 5, '366', 10.555, True] >>> >>> newList = [] >>> >>> >>> aStr = "" >>> >>> aStr '' >>> newList [] >>> >>> >>> len( newList) 0 >>> >>> aList ['245', 5, '366', 10.555, True] >>> >>> >>> '245' in aList True >>> >>> >>> 5 in aList True >>> >>> >>> 7 in aList False >>> >>> >>> >>> range(5) range(0, 5) >>> >>> >>> list( range(5) ) [0, 1, 2, 3, 4] >>> >>> >>> aList ['245', 5, '366', 10.555, True] >>> >>> >>> aList ['245', 5, '366', 10.555, True] >>> aList[0] '245' >>> >>> >>> '245'[1] '4' >>> >>> >>> aList[0] '245' >>> aList[0][1] '4' >>> >>> >>> >>> temp = aList[0] >>> temp '245' >>> temp[1] '4' >>> >>> >>> >>> >>> newList [] >>> >>> newList.append(5) >>> >>> newList [5] >>> >>> >>> newList.append("Jay") >>> >>> newList [5, 'Jay'] >>> >>> >>> newList[0] 5 >>> >>> >>> del newList[0] >>> >>> newList ['Jay'] >>> >>> >>> >>> >>> newList ['Jay'] >>> newList[0] 'Jay' >>> newList[0] = [] >>> >>> newList [[]] >>> newList.append([]) >>> newList.append([]) >>> >>> newList [[], [], []] >>> newList[0] [] >>> newList[0].append(5) >>> >>> newList [[5], [], []] >>> newList[1].append(10) >>> newList [[5], [10], []] >>> newList[2].append(7) >>> >>> newList [[5], [10], [7]] >>> >>> >>> newList[1].append("test") >>> >>> newList [[5], [10, 'test'], [7]] >>> >>> >>> newList[1] [10, 'test'] >>> newList[1][0] 10 >>> newList[1][1] 'test' >>> >>> >>> >>> >>> newList [[5], [10, 'test'], [7]] >>> newList[5] Traceback (most recent call last): File "", line 1, in newList[5] IndexError: list index out of range >>> >>> newList[5] = "hate' SyntaxError: EOL while scanning string literal (, line 1) >>> newList[5] = "blah" Traceback (most recent call last): File "", line 1, in newList[5] = "blah" IndexError: list assignment index out of range >>> >>> >>> newList.append("test") >>> newList [[5], [10, 'test'], [7], 'test'] >>> >>> newList.append(None) >>> >>> newList [[5], [10, 'test'], [7], 'test', None] >>> >>> >>> aList = [4, 10, 18, 33] >>> >>> >>> acc = 0 >>> >>> for item in aList: acc = acc + item >>> acc 65 >>> sum( aList) 65 >>> >>> acc / len(aList) 16.25 >>> >>> >>> >>> aList [4, 10, 18, 33] >>> >>> index = 0 >>> acc = 0 >>> while( index < len(aList)): item = aList[index] acc = acc + item index = index + 1 >>> acc 65 >>> index = 0 >>> acc = 0 >>> while( index < len(aList)): item = aList[index] acc = acc + item index = index + 1 print("item", item, "is at pos", index) item 4 is at pos 1 item 10 is at pos 2 item 18 is at pos 3 item 33 is at pos 4 >>> item 33 is at pos 4 SyntaxError: invalid syntax (, line 1) >>> >>> >>> >>> >>> for item in aList: print(item) 4 10 18 33 >>> >>> >>> count = 0 >>> for item in aList: print(item, "was at", count) count = count + 1 4 was at 0 10 was at 1 18 was at 2 33 was at 3 >>> aList [4, 10, 18, 33] >>> >>> >>> aList + [4,5,6] [4, 10, 18, 33, 4, 5, 6] >>> >>> >>> >>> aList + 4 Traceback (most recent call last): File "", line 1, in aList + 4 TypeError: can only concatenate list (not "int") to list >>> >>> >>> aList + [4] [4, 10, 18, 33, 4] >>> >>> >>> >>> aList [4, 10, 18, 33] >>> >>> >>> aList.append(4) >>> >>> aList [4, 10, 18, 33, 4] >>> [4, 10, 18, 33, 4] [4, 10, 18, 33, 4] >>> >>> aList [4, 10, 18, 33, 4] >>> >>> >>> >>> aList = aList + aList >>> >>> >>> aList [4, 10, 18, 33, 4, 4, 10, 18, 33, 4] >>> aList [4, 10, 18, 33, 4, 4, 10, 18, 33, 4] >>> >>> aList [4, 10, 18, 33, 4, 4, 10, 18, 33, 4] >>> aList.append("Jay") >>> >>> aList.append("Jay").append("bob") Traceback (most recent call last): File "", line 1, in aList.append("Jay").append("bob") AttributeError: 'NoneType' object has no attribute 'append' >>> >>> aList.append(5) >>> >>> >>> aString = "test" >>> >>> aString.replace("t","q") 'qesq' >>> 'qesq'.replace("e","K") 'qKsq' >>> >>> aString 'test' >>> aString.replace("t","q").replace("e","k") 'qksq' >>> >>> >>> aList [4, 10, 18, 33, 4, 4, 10, 18, 33, 4, 'Jay', 'Jay', 5] >>> aList.append(10) >>> >>> >>> aList [4, 10, 18, 33, 4, 4, 10, 18, 33, 4, 'Jay', 'Jay', 5, 10] >>> >>> aList [4, 10, 18, 33, 4, 4, 10, 18, 33, 4, 'Jay', 'Jay', 5, 10] >>> b = aList >>> >>> >>> b [4, 10, 18, 33, 4, 4, 10, 18, 33, 4, 'Jay', 'Jay', 5, 10] >>> b [4, 10, 18, 33, 4, 4, 10, 18, 33, 4, 'Jay', 'Jay', 5, 10] >>> b.apend("bob") Traceback (most recent call last): File "", line 1, in b.apend("bob") AttributeError: 'list' object has no attribute 'apend' >>> b.append("bob") >>> >>> b [4, 10, 18, 33, 4, 4, 10, 18, 33, 4, 'Jay', 'Jay', 5, 10, 'bob'] >>> >>> >>> >>> >>> result = b.append("ted") >>> >>> type(result) >>> aList.append(45) == None True >>> >>> >>> aList [4, 10, 18, 33, 4, 4, 10, 18, 33, 4, 'Jay', 'Jay', 5, 10, 'bob', 'ted', 45] >>> >>> >>> >>> aStr = "test" >>> >>> >>> aStr.replace("t","q") 'qesq' >>> >>> >>> temp = aStr.replace("t","q") >>> >>> >>> temp 'qesq' >>> aStr 'test' >>> >>> aStr = aStr.replace("t","q") >>> >>> >>> aStr 'qesq' >>> aList [4, 10, 18, 33, 4, 4, 10, 18, 33, 4, 'Jay', 'Jay', 5, 10, 'bob', 'ted', 45] >>> type( aList) >>> >>> >>> type( aList.append(10) ) >>> >>> >>> >>> SyntaxError: invalid syntax (, line 1) >>> aList [4, 10, 18, 33, 4, 4, 10, 18, 33, 4, 'Jay', 'Jay', 5, 10, 'bob', 'ted', 45, 10] >>> type( aList) >>> >>> >>> aList [4, 10, 18, 33, 4, 4, 10, 18, 33, 4, 'Jay', 'Jay', 5, 10, 'bob', 'ted', 45, 10] >>> >>> >>> aList + aList [4, 10, 18, 33, 4, 4, 10, 18, 33, 4, 'Jay', 'Jay', 5, 10, 'bob', 'ted', 45, 10, 4, 10, 18, 33, 4, 4, 10, 18, 33, 4, 'Jay', 'Jay', 5, 10, 'bob', 'ted', 45, 10] >>> >>> >>> >>> >>> aList [4, 10, 18, 33, 4, 4, 10, 18, 33, 4, 'Jay', 'Jay', 5, 10, 'bob', 'ted', 45, 10] >>> >>> aList = aList + aList >>> >>> aList [4, 10, 18, 33, 4, 4, 10, 18, 33, 4, 'Jay', 'Jay', 5, 10, 'bob', 'ted', 45, 10, 4, 10, 18, 33, 4, 4, 10, 18, 33, 4, 'Jay', 'Jay', 5, 10, 'bob', 'ted', 45, 10] >>> aList = [4,5,6] >>> >>> >>> aList = aList.append(aList) >>> >>> aList >>> aList >>> >>> >>> type(aList) >>> aList = [4,5] >>> >>> aList.append(aList) >>> >>> >>> aList [4, 5, [...]] >>> for item in aList: print item SyntaxError: invalid syntax (, line 2) >>> for item in aList: print(item) 4 5 [4, 5, [...]] >>>