Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 16 Online
OpenStudy (anonymous):

What's the difference btw () and [] in python!? Thanks in advance!

OpenStudy (anonymous):

() is used by functions [] is used by lists

OpenStudy (anonymous):

also a = [1,2,3,4,5] produces a list b = (1,2,3,4,5) produces a tuple lists can be modified after creation: a[2] = 7 is fine tuples cannot: b[2] = 7 results in an error

OpenStudy (anonymous):

What are differences between tuple and list? When should I use list over tuple or the other way around? It looks like a list is better since you can modify the assignment of the elements inside the bracket. Thank you for your help!

OpenStudy (rsmith6559):

You pretty much answered your own question. If you want a collection to be immutable (can't be changed), a tuple is a better choice. If you want the same type of collection to be mutable (changeable), a list is a better choice.

OpenStudy (anonymous):

Thank you guys for the help! I recently started to watch this course to learn some of program language. When listening to lectures, everything sounds straight forward, but when trying to solve problem sets, everything turns into a mess! haha

OpenStudy (anonymous):

() is an empty tuple, [] is an empty list

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!