Python 3.8.7 (tags/v3.8.7:6503f05, Dec 21 2020, 17:59:51) [MSC v.1928 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license()" for more information. >>> str1="word" >>> str1[0] 'w' >>> str1[-3] 'o' >>> str1[-4] 'w' >>> len(str1) 4 >>> str1[len(str1)-1] 'd' >>> str1[-1] 'd' >>> position=2 >>> str1[position] 'r' >>> str1[0:2] 'wo' >>> str1="today is monday!" >>> len(str1) 16 >>> str2[0:4] Traceback (most recent call last): File "", line 1, in str2[0:4] NameError: name 'str2' is not defined >>> str1[0:4] 'toda' >>> str1[0:4] 'toda' >>> str1[0:5] 'today' >>> str1[6] 'i' >>> str1[6:8] 'is' >>> str1[-1:-7] '' >>> str1[-7] 'm' >>> str1[-7:-1] 'monday' >>> str1[0:5] 'today' >>> str1[:5] 'today' >>> str1[:] 'today is monday!' >>> str1[6:] 'is monday!' >>> myList=[2,4,6,8,10,20,50,200,"today",[2,4,6]] >>> len(myList) 10 >>> myList[2] 6 >>> myList[0] 2 >>> myLIst[0:6] Traceback (most recent call last): File "", line 1, in myLIst[0:6] NameError: name 'myLIst' is not defined >>> myList[0:6] [2, 4, 6, 8, 10, 20] >>> myList[:6] [2, 4, 6, 8, 10, 20] >>> myList[-1] [2, 4, 6] >>> myList[9] [2, 4, 6] >>> myList[len(myList)-1] [2, 4, 6] >>> str2="2,4,6" >>> str3="MONDAY!" >>> str2+str3 '2,4,6MONDAY!' >>> listTwo=['a','b','d'] >>> myList+listTwo [2, 4, 6, 8, 10, 20, 50, 200, 'today', [2, 4, 6], 'a', 'b', 'd'] >>> myList[-2] 'today' >>> myLIst[-2:0] Traceback (most recent call last): File "", line 1, in myLIst[-2:0] NameError: name 'myLIst' is not defined >>> myList[-2,0] Traceback (most recent call last): File "", line 1, in myList[-2,0] TypeError: list indices must be integers or slices, not tuple >>> myList[-2:0] [] >>> myList[-2:-1] ['today'] >>> type(myList[-2]) >>> type(myList[-2:-1]) >>> myList [2, 4, 6, 8, 10, 20, 50, 200, 'today', [2, 4, 6]] >>> index=0 >>> for item in myList: print[index] index=index+1 Traceback (most recent call last): File "", line 2, in print[index] TypeError: 'builtin_function_or_method' object is not subscriptable >>> index=0 >>> for item in myList: print(myLIst[index]) index=index+1 Traceback (most recent call last): File "", line 2, in print(myLIst[index]) NameError: name 'myLIst' is not defined >>> index=0 >>> for item in myList: print(myList[index]) index=index+1 2 4 6 8 10 20 50 200 today [2, 4, 6] >>> index=0 >>> for item in myList: print(type(myList[index])) index=index+1 >>> index=0 >>> for index in range(len(myList)): print(myList[index:inex+1]) Traceback (most recent call last): File "", line 2, in print(myList[index:inex+1]) NameError: name 'inex' is not defined >>> index=0for index in range(len(myList)): print(myList[index:index+1]) SyntaxError: invalid syntax >>> >>> index=for index in range(len(myList)): print(myList[index:index+1]) SyntaxError: invalid syntax >>> index=0 >>> for index in range(len(myList)): print(myList[index:index+1]) [2] [4] [6] [8] [10] [20] [50] [200] ['today'] [[2, 4, 6]] >>> index=0 >>> for index in range(len(myList)): print(type(myList[index:index+1])) >>> score=3 >>> grades="FFDCBA" >>> print(grades[score]) C >>> grades=["A","B","C","D","F","f"] >>> grades=["F","f","D","C","B","A"] >>> >>> str1="monday" >>> str1[0] 'm' >>> str1[0]="M" Traceback (most recent call last): File "", line 1, in str1[0]="M" TypeError: 'str' object does not support item assignment >>> str1="Monday' SyntaxError: EOL while scanning string literal >>> str1="Monday" >>> str1 'Monday' >>> listOne=[2,4,6,8] >>> listOne[0] 2 >>> listOne[0]="Monday" >>> listOne ['Monday', 4, 6, 8] >>> listOne[0][0] 'M' >>> listOne[0][-1] 'y' >>> listOne[1][-1] Traceback (most recent call last): File "", line 1, in listOne[1][-1] TypeError: 'int' object is not subscriptable >>> listOne ['Monday', 4, 6, 8] >>> listOne[1.00000789] Traceback (most recent call last): File "", line 1, in listOne[1.00000789] TypeError: list indices must be integers or slices, not float >>> listOne[int(1.00000789)] 4 >>> str1="monday" >>> str1.capitalize() 'Monday' >>> str1 'monday' >>> str2=str1.capitalize() >>> str2 'Monday' >>> str1 'monday' >>> str1=str1.capitalize() >>> >>> str1 'Monday' >>> str1.upper() 'MONDAY' >>> str1 'Monday' >>> str2="today is monday" >>> str2.title() 'Today Is Monday' >>> str2 'today is monday' >>> nameOne="Thomas" >>> nameTwo="Harris-Smith" >>> nameOne.rjust(50) ' Thomas' >>> nameTwo.rjust(50) ' Harris-Smith' >>> nameOne.ljust(30) 'Thomas ' >>> name2.ljust(30) Traceback (most recent call last): File "", line 1, in name2.ljust(30) NameError: name 'name2' is not defined >>> nameTwo.ljust(30) 'Harris-Smith ' >>> nameTwo.center(30) ' Harris-Smith ' >>> nameOne.center(30) ' Thomas ' >>> listOne=["Today","is","Monday"] >>> "".join(listOne) 'TodayisMonday' >>> listTwo=[2,4,6,8] >>> "",join(listTwo) Traceback (most recent call last): File "", line 1, in "",join(listTwo) NameError: name 'join' is not defined >>> " ".join(listOne) 'Today is Monday' >>> sentence=" ".join(listOne) >>> sentence 'Today is Monday' >>> senence.split() Traceback (most recent call last): File "", line 1, in senence.split() NameError: name 'senence' is not defined >>> sentence.split() ['Today', 'is', 'Monday'] >>> sentence 'Today is Monday' >>> len(sentence) 15 >>> listOfWords=sentence.split() >>> listOfWords ['Today', 'is', 'Monday'] >>> len(listOfWords) 3 >>> letterCount=0 >>> for word in listOfWords: letterCount=letterCount+len(word) >>> letterCount 13 >>>