+ 1
What is the difference between a list and a tuple?
2 ответов
+ 11
► Syntax for creating a list : list_demo = [1,2,3,4] which is surrounded by square brackets while syntax for creating a tuple : tuple_demo = (1,2,3,4) which is surrounded by round brackets.
► You can check the list of available functions in the both of them by using dir() which is an inbuilt function. Use dir(list_demo) and dir(tuple_demo), you'll clearly understand the difference in their features. (If you carefully observed, then lists have more functions as compared to tuples)
► The most important difference is that the lists are mutable in nature (they can be modified after creating them) while tuples are immutable (they cannot be modified after their creation). Try list_demo[1] = 8 and print(list_demo). Do same with tuples, tuple_demo[1] = 8 and print(tuple_demo), here you'll be getting an error.
Hope this was sufficient for you to understand the difference !!
+ 3
Thank you both of you