From the course: Certified Entry-Level Python Programmer (PCEP-30-02) Cert Prep
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Using tuples - Python Tutorial
From the course: Certified Entry-Level Python Programmer (PCEP-30-02) Cert Prep
Using tuples
- [Instructor] Now it's time to talk about tuples. Tuples are very similar to list. In fact, I can open one of my list such as, for example, the list of countries, paste them here and change square brackets with parenthesis. And now we have a tuple. So if I print countries, I'm seeing something similar, in this case with parenthesis and if I ask about the type, now it's not a class list, it's a class tuple. So what's the main difference? Well, it's immutable. So we cannot remove or change elements. So for example, if I want to change one country with a list, I will use something like this. So I'm changing in Brazil, I'm adding USA. However, this is not going to work and I'm getting a type error. The tuple object does not support item assignment. So I cannot change values, append values, or insert new values in a tuple after it was set. So that's like the main difference that we have. Also, a tuple can be expressed…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.