Posts

Showing posts from July, 2024

CONVERTING TUPLE INTO LIST AND LIST INTO TUPLE

  mytuple = ( "i" , "love" , "python" ) list1=list(mytuple) #Write the missing code here print( "Given Tuple:" ,mytuple) print( "After Converting Tuple into List:" ,list1) list1[ 1 ]= "practice" print( "List after changing element:" ,list1) tuple1=tuple(list1) print( "After Converting List into Tuple:" ,tuple1) OUTPUT: Test case 1 Given · Tuple: · ('i', · 'love', · 'python') ⏎ After · Converting · Tuple · into · List: · ['i', · 'love', · 'python'] ⏎ List · after · changing · element: · ['i', · 'practice', · 'python'] ⏎ After · Converting · List · into · Tuple: · ('i', · 'practice', · 'python') ⏎

PYTHON TUPLE PROGRAM

  mytuple = ( "this" , 10.0 , "is" , "float" , 3.6 ) # Print value at index 0 print(mytuple[ 0 ]) # Print value at index 1 print(mytuple[ 1 ]) # Print value at index -1 print(mytuple[ 4 ]) # Print all the values from index 0 print(mytuple[ 0 : 5 : 1 ]) # Print all the values except the last value print(mytuple[ 0 : 4 : 1 ]) print(mytuple[- 1 :- 6 :- 1 ]) OUTPUT: this 10.0 ⏎ 3.6 ⏎ ('this', · 10.0, · 'is', · 'float', · 3.6) ⏎ ('this', · 10.0, · 'is', · 'float') ⏎ (3.6, · 'float', · 'is', · 10.0, · 'this') ⏎