InterviewSolution
Saved Bookmarks
| 1. |
Tuples in Python |
|
Answer» Tuples are entities in Python that work almost similar to that of lists, but differ in the main feature from lists, is in that they are inmutable. They are initialized by writing the elements of the tuple with (), separated by commas. # Defining and Initializing a tuple called exampleexample = ("First", "Second", "Third", "Fourth") print(example) print(example[1:3]) Output: ('First', 'Second', 'Third', 'Fourth') ('Second', 'Third') Type Converting between Tuples, Lists, and Strings: # Convert list to a tupletuple(['first', 'second', 'third']) # Convert tuple to a list list(('first', 'second', 'third')) # Convert string to a list list("Scaler") |
|