Let's now look at tuples. In the previous lecture we looked at lists and
tuples are very similar to lists, the only difference is that tuples are not
mutable, so you cannot change a tuple. Lists are used much more than tuples
so tuples are only using very specific scenarios, so we will see some scenarios
throughout the course when we build the real-world applications, so you don't
have to worry about understanding when to use a tuple in programming for now.
Anyway I want to show you the syntax, so you can create a tuple like that.
So tuples just like lists, they contain they may contain different data types.
Let's say 3 4 and so on. Oh sorry, I was writing in the
terminal, let me open the Python shell so again
we have strings numbers and floats if you like. Whatever type that you want you can pass
in a tuple and in a list and of course you can use indexing for tuples as well,
so let's access the lost item and that will give 4.6. The difference is that you
know tuples they have some slight different methods than lists, so if you
dir list, you see that lists have much more methods available than tuples,
so for instance you can append items to a list, you can clear the list and copy
and count, count is available for tuples because count doesn't change the data type,
so it doesn't change the tuple, it just counts how many items are there in the tuple.
As I said, tuples are immutable, so you cannot change them that's why these
methods that change the data type like inserting new values and popping out
values, removing values, reversing and sorting so these
are not available and yeah this is more or less about tuples. In case you need them
later they are there for you. Hope you're enjoying the course and I'll talk to you later.