Python Programming Tutorial #8 - Lists and Tuples

Tech With Tim · Beginner ·🛠️ AI Tools & Apps ·9y ago

Key Takeaways

This video tutorial covers the basics of lists and tuples in Python, including creating, accessing, and modifying list elements, as well as introducing tuples as a separate data type.

Full Transcript

hey guys welcome back to the eighth video in my Python Programming Series today we're going to be talking about list Now list can be fairly complex uh but they are a very important part of python and they are very important to understand so a list is another data type so before we talked about strings integers booleans and floating decimal points so floats um and today we're going to talk about lists so lists again are their own data type so let's just start off by doing an example right now so pretty much uh a list which is denoted by the square brackets here uh is a collection of different data types it could be the same data types or it can be different data types so for an example I'm going to put a apple in here in my list I'm going to put a comma and I'm going to add another item so maybe we'll put a pair and then maybe we'll put a number as well okay so we have the list fruits and in the list we have three items um now everything here separated by a comma is known as an item item so for an example our apple is an item our pair is an item and the integer three is an item now you can see that they're all different data types or sorry there is different data types we have two strings and we have one integer value um now this is fine you can store um different data types in one list um okay so now let's just print the list to the console so we can see what it looks like print it out and you'll see we simply get what exactly what we've typed uh into the idle so we get apple pair and three now if we want to access an individual item in the list we need to do something um a little different so right now we just printed out the whole list but say we want to just print out pair um now what we're going to do is we're going to use the square brackets so we're going to do the list name so fruits and then we're going to put square brackets right beside it no spaces and then inside of the square bracket we're going to type in what's known as the indic of that item um so the way indices work in Python is when you create a list everything is automatically assigned in indic um so in this list we have indices 0 through two now it may seem weird that we start at Z instead of one but that's just the way that computers count um and the way that they work so we have to understand that apple is going to be assigned the integer value of zero so the indic zero meaning I would put zero in here if I wanted to access Apple because that's the first element in our list and then we have pair so that's the second element or item um now that's actually going to be represented by one here so fruits one will give us the value of pair and then fruits two will give us the value of three um now this is uh sometimes difficult for some people to understand but just really try to remember that the first item always is zero so if you would like to access the second item in your list you're going to type in one um into the indic thing here okay so I'm just going to run this and show you how this works and you see we get pair okay that's because um we have the first indic which represents the second item which is pair okay um now there's some other things we can do with list as well so if we want to add something to our list there's a few ways that we can do it um the first way uh which is the only one I'm going to show you right now is probably the easiest and simply what we're going to type is fruits followed by the dot uh so a DOT a period and then we're going to type a pen okay now this means to add to the end of the list so inside of a pend I'm going to put the element or the item that I'd like to add so say we want to add uh another fruit let's think of another fruit that we could add maybe a strawberry okay we want to add strawberry into the list I'm just going to get rid of three so it makes more sense okay so right now now in our list up here we have fruits which is a variable name um containing the list that has Apple and pear now we want to add strawberry to the list so let's start off by printing the list before we add it so we'll print off fruits and then we're going to print fruits one more time after we add this item to the list and you see we have the first list which is what we defined originally and then when we added or appended strawberry to the end of it it added it in just like this so that is a way that we are able to add things into a list um by using do append now there is another way um it's known as the slice operator using something called insert um but we're not going to do that right now we're going to talk about the slice operator in a later tutorial so stay tuned for that okay so fruits. aend we've added strawberry um now if we wanted to add another item we could do the same thing and we could do append again and we we could put in another fruit maybe we want to put in a blueberry okay just like that and again we'll see that it does the same thing we have apple pear and then apple pear strawberry blueberry okay um all right so that's it for adding to the list um now what about changing something in our list uh so let's just add right here at the beginning we'll put in Strawberry so we have three items and now let's say we want to change the middle item in our list to a different fruit say we don't like peirs we want to remove it we want to change that so what we're going to do is we're simply going to type the um the name again so fruits followed by the square brackets and then the indic of the item you want to change um so again remember if we want to change pair we're going to use the indic one um not two because this is the way that it works we're going to use one and then we're going to change it to whatever we' like to change it to so say I want to change it to Blueberry I can do that like like so and then again we can print out fruits and we'll see if it works okay so we get apple blueberry and strawberry that's because we've changed uh the item at indic one into blueberry and we've replaced that we replaced Paar with blueberry pretty much okay um so that's how that works for list for changing items again um we you lists are very useful for storing large amounts of information so this is a very small list but in many programs we use something called multi-dimensional list uh which I'm going to talk about again in another tutorial um and yeah so one more thing before we end it here uh there's another data type called a tupal so a tuple um it's kind of hard word to pronounce but it's used for coordinates and it's also used um for things like colors and rectangles angles um it can also be used just to hold information as well but it's a different type of data type um than a list so we're going to talk about it quickly uh okay so a tuple pretty much looks like this so if we set a position and we set it equal to something like this not in square brackets in the regular round brackets and then we simply put um the items in like this now we see we get um it looks very similar to a list the way that it works again we can use different data types so I could put some like hello in here as well um but it does function a little differently and again things like colors we would also store in a tupo so we would use like 255 255 255 that's simply white in uh red green blue colors and again if we print out the type of the color you can see that we get a class tupal okay so I'm not going to go too in depth with the tupal here I just wanted you to understand what they are because we may be using them in some later to tutorials okay so I hope you learned how to use lists and a little bit about tupal today they're going to be important in the next tutorial um so yeah I hope you enjoyed if you did please like And subscribe and I will see you in the next video

Original Description

This is the 8th video in my python programming tutorial series. Today I cover lists and tuples. A list is a collection datatype that can stores multiple values of various data types. To access an element in a list we simply type the list name followed by square brackets (fruits[2]). Text-Based Tutorial: https://techwithtim.net/tutorials/python-programming/beginner-python-tutorials/lists-and-tuples/ Please do not forget to LIKE the video and SUBSCRIBE for more tutorials and other content daily. Video Tags: python,python tutorial,python language,python full course,python course,learn python,learn python programming,python tutorial for beginners,python tutorial 2018,python programming tutorial,python programming language,software development,programming tutorial,tech with tim
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Tech With Tim · Tech With Tim · 9 of 60

1 A* Path Finding Algorithm(Visualization)
A* Path Finding Algorithm(Visualization)
Tech With Tim
2 Python Programming Tutorial #1 - Variables and Data Types
Python Programming Tutorial #1 - Variables and Data Types
Tech With Tim
3 Python Programming Tutorial #2 - Basic Operators and Input
Python Programming Tutorial #2 - Basic Operators and Input
Tech With Tim
4 Python Programming Tutorial #3 - Conditions
Python Programming Tutorial #3 - Conditions
Tech With Tim
5 Python Programming Tutorial #4 - IF/ELIF/ELSE
Python Programming Tutorial #4 - IF/ELIF/ELSE
Tech With Tim
6 Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Tech With Tim
7 Python Programming Tutorial #6 - For Loops
Python Programming Tutorial #6 - For Loops
Tech With Tim
8 Python Programming Tutorial #7 - While Loops
Python Programming Tutorial #7 - While Loops
Tech With Tim
Python Programming Tutorial #8 - Lists and Tuples
Python Programming Tutorial #8 - Lists and Tuples
Tech With Tim
10 Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Tech With Tim
11 Python Programming Tutorial #10 - String Methods
Python Programming Tutorial #10 - String Methods
Tech With Tim
12 How to Overclock a NVIDIA GPU
How to Overclock a NVIDIA GPU
Tech With Tim
13 Python Programming Tutorial #11 - Slice Operator
Python Programming Tutorial #11 - Slice Operator
Tech With Tim
14 Python Programming Tutorial #12 - Functions
Python Programming Tutorial #12 - Functions
Tech With Tim
15 Python Programming Tutorial #13 - How to Read a Text File
Python Programming Tutorial #13 - How to Read a Text File
Tech With Tim
16 Python Programming Tutorial #14 - Writing to a Text File
Python Programming Tutorial #14 - Writing to a Text File
Tech With Tim
17 Python Programming Tutorial #15 - Using .count() and .find()
Python Programming Tutorial #15 - Using .count() and .find()
Tech With Tim
18 Python Programming Tutorial #16 - Introduction to Modular Programming
Python Programming Tutorial #16 - Introduction to Modular Programming
Tech With Tim
19 Python Programming Tutorial #17 - Optional Parameters
Python Programming Tutorial #17 - Optional Parameters
Tech With Tim
20 Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Tech With Tim
21 Python Programming Tutorial #19 - Global vs Local Variables
Python Programming Tutorial #19 - Global vs Local Variables
Tech With Tim
22 Python Programming Tutorial #20 - Classes and Objects
Python Programming Tutorial #20 - Classes and Objects
Tech With Tim
23 Cool VBS Script to Prank Your Friends!
Cool VBS Script to Prank Your Friends!
Tech With Tim
24 How to Overclock an AMD GPU
How to Overclock an AMD GPU
Tech With Tim
25 Best GPU'S For Mining Ethereum (2018)
Best GPU'S For Mining Ethereum (2018)
Tech With Tim
26 Recursion and Memoization Tutorial Python
Recursion and Memoization Tutorial Python
Tech With Tim
27 Ethereum Mining Rig - Hardware Guide
Ethereum Mining Rig - Hardware Guide
Tech With Tim
28 Pygame Tutorial #1 - Basic Movement and Key Presses
Pygame Tutorial #1 - Basic Movement and Key Presses
Tech With Tim
29 How to Install Pygame (Windows 8/10)
How to Install Pygame (Windows 8/10)
Tech With Tim
30 How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
Tech With Tim
31 How to Mine Ethereum 2018 - WORKING (Super-Easy)
How to Mine Ethereum 2018 - WORKING (Super-Easy)
Tech With Tim
32 Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Tech With Tim
33 Pygame Tutorial #2 - Jumping and Boundaries
Pygame Tutorial #2 - Jumping and Boundaries
Tech With Tim
34 Pygame Tutorial #3 - Character Animation & Sprites
Pygame Tutorial #3 - Character Animation & Sprites
Tech With Tim
35 Pygame Tutorial #4 - Optimization & OOP
Pygame Tutorial #4 - Optimization & OOP
Tech With Tim
36 OBS Studio Tutorial - Best OBS Settings
OBS Studio Tutorial - Best OBS Settings
Tech With Tim
37 Linear Search Algorithm - Python Example and Code
Linear Search Algorithm - Python Example and Code
Tech With Tim
38 Make Any Mic Sound AMAZING! (WITH OBS)
Make Any Mic Sound AMAZING! (WITH OBS)
Tech With Tim
39 Binary Search Algorithm - Python Example & Code
Binary Search Algorithm - Python Example & Code
Tech With Tim
40 Pygame Tutorial #5 - Projectiles
Pygame Tutorial #5 - Projectiles
Tech With Tim
41 Pygame Game - Mini Golf
Pygame Game - Mini Golf
Tech With Tim
42 Pygame Tutorial - Projectile Motion (Part 1)
Pygame Tutorial - Projectile Motion (Part 1)
Tech With Tim
43 Pygame Tutorial - Projectile Motion (Part 2)
Pygame Tutorial - Projectile Motion (Part 2)
Tech With Tim
44 Pygame Tutorial #6 - Enemies
Pygame Tutorial #6 - Enemies
Tech With Tim
45 Pygame Tutorial #7 - Collision and Hit Boxes
Pygame Tutorial #7 - Collision and Hit Boxes
Tech With Tim
46 Pygame Tutorial #8 - Scoring and Health Bars
Pygame Tutorial #8 - Scoring and Health Bars
Tech With Tim
47 Cloud Mining vs. Hardware Mining - 2018
Cloud Mining vs. Hardware Mining - 2018
Tech With Tim
48 How to Install Pygame on Mac OSX (Fast-Simple)
How to Install Pygame on Mac OSX (Fast-Simple)
Tech With Tim
49 Pygame Tutorial #9 - Sound Effects, Music & More Collision
Pygame Tutorial #9 - Sound Effects, Music & More Collision
Tech With Tim
50 Pygame Tutorial #10 - Finishing Touches & Next Steps
Pygame Tutorial #10 - Finishing Touches & Next Steps
Tech With Tim
51 How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
Tech With Tim
52 How to Create a Button in Pygame [CODE IN DESCRIPTION]
How to Create a Button in Pygame [CODE IN DESCRIPTION]
Tech With Tim
53 Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Tech With Tim
54 Pygame Side-Scroller Tutorial #2 - Random Object Generation
Pygame Side-Scroller Tutorial #2 - Random Object Generation
Tech With Tim
55 Pygame Side-Scroller Tutorial #3 - Collision
Pygame Side-Scroller Tutorial #3 - Collision
Tech With Tim
56 Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Tech With Tim
57 How to Create A Message Box in Python - Tkinter
How to Create A Message Box in Python - Tkinter
Tech With Tim
58 Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Tech With Tim
59 How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
Tech With Tim
60 Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Tech With Tim

This tutorial teaches the basics of lists and tuples in Python, including how to create, access, and modify list elements, and introduces tuples as a separate data type. Understanding these concepts is essential for working with data in Python.

Key Takeaways
  1. Create a list in Python using square brackets
  2. Access a list element using its index
  3. Modify a list element using its index
  4. Add an element to a list using the append method
  5. Create a tuple in Python using round brackets
  6. Understand the difference between lists and tuples
💡 Lists and tuples are fundamental data structures in Python, and understanding how to work with them is crucial for any Python programmer.

Related Reads

📰
How I Built a Free Online Image & PDF Processing Platform with Vue 3 + FastAPI
Learn how to build a free online image and PDF processing platform using Vue 3 and FastAPI, and discover the benefits of combining these technologies for efficient file processing
Dev.to · IAMUU
📰
I Built a Free AI-Powered YouTube SEO Toolkit With Zero Budget. Here’s What Actually Happened.
Learn how a solo dev built a free AI-powered YouTube SEO toolkit with zero budget and the lessons they learned from the experience
Medium · Startup
📰
How to Create a Second Version of Yourself Inside Obsidian Using AI (Step-by-Step Guide)
Learn to create a second version of yourself inside Obsidian using AI with a step-by-step guide
Medium · ChatGPT
📰
How to prepare for Spain civil service TIC exam using AI in 2026
Learn how to prepare for the Spain civil service TIC exam using AI in 2026, boosting your chances of success with technology-driven study techniques
Dev.to · David García
Up next
I Asked Gemini to Build a Dashboard... I Didn't Expect This
Patech
Watch →