Python Tutorial for Beginners 4: Lists, Tuples, and Sets

  • Published on May 17, 2017
  • In this Python Beginner Tutorial, we will begin learning about Lists, Tuples, and Sets in Python. Lists and Tuples allow us to work with sequential data, and Sets allow us to work with unordered unique values. We will go over most of the methods, learn when to use which data type, and also the performance benefits of each type as well. Let's get started.
    The code from this video can be found at:
    Watch the full Python Beginner Series here:
    Slicing Video:

    ✅ Support My Channel Through Patreon:
    ✅ Become a Channel Member:
    ✅ One-Time Contribution Through PayPal:
    ✅ Cryptocurrency Donations:
    Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
    Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
    Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
    ✅ Corey's Public Amazon Wishlist
    ✅ Equipment I Use and Books I Recommend:
    ▶️ You Can Find Me On:
    My Website -
    My Second Channel -
    Facebook - CoreyMSchafer
    Twitter - CoreyMSchafer
    Instagram - coreymschafer

Comments • 466

  • Mr. Carnage
    Mr. Carnage 13 hours ago

    Which python IDE is he using for coding?

    • Corey Schafer
      Corey Schafer  12 hours ago

      Hey There. I use Sublime Text for my tutorials since it's pretty minimalist. I also use VSCode for my day-to-day coding. I made a video on how I set up my Python development environment in both of those editors. You can find those videos here:
      Sublime Text -
      VSCode -

    HYPER LIGHT 2 days ago +2

    Thanks , realy helpfull

  • pc722800
    pc722800 2 days ago

    what is the name of the plugin used to comment multiple lines at a time?

  • Khalil Carlosse
    Khalil Carlosse 2 days ago +1

    Ah yes my favorite subject: Education

  • stayangrystayfoolish

    May I ask very baby question? Do I have to remember all command to have a job as a programmer?

  • ravjot singh
    ravjot singh 4 days ago

    #convert the positive list into negative with user input
    a = input("enter the list").split(",")
    def negative(b):
    neg = []
    for i in b:
    return neg

    I am getting an error.
    Traceback (most recent call last):
    File "", line 9, in
    File "", line 7, in negative
    TypeError: bad operand type for unary -: 'str'

  • Kevin Ha
    Kevin Ha 6 days ago +1

    The best tutorial for Python !!! Great job !!!

  • dinushka piyumal
    dinushka piyumal 14 days ago


  • pravin kalake
    pravin kalake 15 days ago

    @Corey Schafer just a Quick Question. How do you comment and uncomment multiple line of codes?

  • Alex Sage
    Alex Sage 17 days ago

    Let's say I use single ' instead of " but in a list I have 'What's up!' (which has that character in it) how can I make it so that ' character won't counteract? replace it with something?

  • Igor Nikachin
    Igor Nikachin 18 days ago +1

    Corey, i fucking love. YOU ARE THE MAN!!!!

  • Alex Sage
    Alex Sage 22 days ago +1

    great tut!

  • Mickey Kr
    Mickey Kr 24 days ago

    Hey sir, My question is what is the role of empty list,tuple or set?

  • Jing Liu
    Jing Liu 24 days ago +2

    I love all your Python courses!!! You are the best!!! I feel so lucky to know you on TheXvid and you get many of my Python issues clear. THANK YOU!!!

  • Louis Balderas
    Louis Balderas 27 days ago +2

    Quick question, what hotkeys are you using to uncomment and comment a block of lines?

    BEST LOGISTICS SAP 28 days ago

    courses = 'hisory','chemisry','biology','maths','science'
    I am getting following error
    Traceback (most recent call last):
    File "/Users/rejiismail/Documents/Python/", line 2, in
    AttributeError: 'tuple' object has no attribute 'append'

      BEST LOGISTICS SAP 28 days ago

      Sorry got it I was not using square bracket at the start of courses.

  • Dennis Will
    Dennis Will 29 days ago +1

    Great overview of the differences between lists and tuples!

  • Jerry Brice
    Jerry Brice Month ago +1

    Superb delivery. Thank you!

  • mike Princivil
    mike Princivil Month ago

    how did he comment out multiple lines like that?

    • zzz000zz
      zzz000zz Month ago

      From the Sublime Text Editor, select Edit > Comment (or "command+/" on a Mac.) You can also un-comment multiple lines but I will let you learn that on your own.

  • Hardik Goel
    Hardik Goel Month ago +1

    4 lessons in I love it

  • Ankur Kumar
    Ankur Kumar Month ago +1

    A valuable note:
    *join()* method works on a list of strings. It won't work on a list of integers.

  • That One User
    That One User Month ago +3

    1:00 - Lists
    22:03 - Tuples
    23:35 - Sets

  • nyes liberty
    nyes liberty Month ago +1

    absolute geginner but im telling you am getting along with every thing here ... thanks man for the great work im really in class while at home.

  • Yogi Peram
    Yogi Peram Month ago +1

    Very useful content.. Thank you

  • ravi chandra
    ravi chandra 2 months ago

    Why does the reverse method on sorted(list) version prints None. s = sorted(existing_list) , print(s.reverse()) //prints None

  • Mohammed Amer
    Mohammed Amer 2 months ago +1

    Thank You So Much!

  • Nitesh Bagla
    Nitesh Bagla 2 months ago +1

    What's the use of creating an empty tuple?

  • Tom
    Tom 2 months ago

    which program are u running your code on?

    • Corey Schafer
      Corey Schafer  2 months ago

      Hey There. I use Sublime Text for my tutorials since it's pretty minimalist. I also use VSCode for my day-to-day coding. I made a video on how I set up my Python development environment in both of those editors. You can find those videos here:
      Sublime Text -
      VSCode -

  • nikhil t
    nikhil t 2 months ago

    del courses[0]
    only legends know this

  • Reza Sadr
    Reza Sadr 2 months ago

    Hi ! I'm enjoying learning with your videos, a question:
    at 16':45'' (the time in the video time), how we can change two identical words at the same time? (here 2'item' change to 'course' at the same time.

    • Issac Wiggins
      Issac Wiggins Month ago

      I know in some editors you can hold CTRL and click on different areas of the text editors and it allows you edit/write over whatever was there previously.

  • Cheerful Channel
    Cheerful Channel 2 months ago +1

    Thanks for the tutorials! it's inspiring me

  • Lelre Ferreira da Silva

    How can I receive informations from the keyboard and save it in a list using for-loop?

  • Esraa Mohamed
    Esraa Mohamed 2 months ago +1

    Thank you for your hard work

  • Akagra Srivastav
    Akagra Srivastav 2 months ago

    Hello Corey
    I have a question regarding empty set.
    When I try to create an empty set using
    empty_set = {}
    If I print empty set, I get {} in the console.
    If I create empty set using
    empty_set = set()
    If I print empty_set here, I get set() in console
    WHY ?

    • Corey Schafer
      Corey Schafer  2 months ago

      empty_set = {} doesn't create a set. It creates an empty dictionary. In order to create an empty set you should use empty_set = set()

  • Micheal Jones
    Micheal Jones 3 months ago +1

    26:06 art students need math, too ;)

  • Reneeke9
    Reneeke9 3 months ago

    HEy Corey! I am trying to remove the duplicates with a function, check out my code.
    def Dduplicates(x): # as in delete the duplicates
    x = set(x)
    x = (x)
    list3 = [4,4,4,4,4,4,5,5,5,5,5,6,6,6,6]

    now when i use my function, it will give me {4, 5 ,6}
    but when i print list3, it will give me all the double nrs again.
    how can i replace the Original list3, with the list3 that is generated from within the function?

  • s baskaravishnu
    s baskaravishnu 3 months ago +1

    your videos are excellent. Your videos are very much useful to me, Many thanks for that. My warm regards to you.

  • Shashwat Tyagi
    Shashwat Tyagi 3 months ago


  • Noam Tamarin
    Noam Tamarin 3 months ago

    could someone tell me how to make the colour of my methods / functions look like Corey's?

    I installed all packages as instructed in the first video, but for example in this video, my 'print', 'append, and '=' aren't pink as his are, they're white

  • Mr Perfect
    Mr Perfect 3 months ago +1

    thanks for such useful lessons

  • Mandeep Vayeda
    Mandeep Vayeda 3 months ago

    why do we create empty lists, tuples, sets?

    • Corey Schafer
      Corey Schafer  3 months ago +1

      It depends on what you're using it for. Sometimes it's used to represent no results.

  • Rohan Sirohia
    Rohan Sirohia 3 months ago

    How print only education of the sub list like at 8:02 where you have showed printing the list stored inside another list

  • Sahil Khotkar
    Sahil Khotkar 3 months ago

    which IDE is this?

    • Corey Schafer
      Corey Schafer  3 months ago

      Hey There. I use Sublime Text for my tutorials since it's pretty minimalist. I also use VSCode for my day-to-day coding. I made a video on how I set up my Python development environment in both of those editors. You can find those videos here:
      Sublime Text -
      VSCode -

    • M.S. Sudarsanan
      M.S. Sudarsanan 3 months ago

      py charm

  • Yosi Gilad
    Yosi Gilad 4 months ago +1

    Thank you!

  • R M
    R M 4 months ago

    Would it be possible to change list items like this?:
    fruits = ['apple', 'orange', 'banana']
    fruits[0] = 'pineapple'
    ['pineapple', 'orange', 'banana']

  • Paterson Djemi
    Paterson Djemi 4 months ago +1

    you are an amazin teacher ! stay blesses. Thanks for sharing all that with us

  • surekha c
    surekha c 4 months ago

    Hi Corey... How to sort alpha numeric list?
    Example:list1=['copy::settings_1.png', 'copy::settings_2.png', 'copy::settings_10.png', 'copy::settings_11.png', 'copy::settings_3.png', 'copy::settings_4.png']

  • Yasin Abdi
    Yasin Abdi 4 months ago

    5:00 physics is actually the third index in the list but you said the second

    • Yasin Abdi
      Yasin Abdi 4 months ago

      @Corey Schafer but you said our second index which is physics while its the third i know its in [2] . but logically if you call physics the second index then what should you call history

    • Corey Schafer
      Corey Schafer  4 months ago

      Yasin Abdi Yep, that will have an index of 2 even though it is the 3rd item

    • Yasin Abdi
      Yasin Abdi 4 months ago

      @Corey Schafer im taking about the item physics index

    • Corey Schafer
      Corey Schafer  4 months ago

      Indexes start at 0. So the third item of them list has an index of 2

  • Shiva
    Shiva 4 months ago +1

    List : 0:00
    Tuple : 20:05
    LIst : 23:34

  • westfield90
    westfield90 4 months ago

    Can you sort a Tuple? If so isn't that mutating the tuple?

    • Corey Schafer
      Corey Schafer  4 months ago

      You can, but it creates a new object instead of modifying the existing object.

  • Time Passer
    Time Passer 4 months ago

    Why some tuples with one item only ends with coma before the closing parenthesis?

  • Himanshu bhandari
    Himanshu bhandari 5 months ago +2

    how you lines and insert # and remove # in front of all lines just pressing a single key(which key??🤔🤔🤔)

  • Steve Glover
    Steve Glover 5 months ago +5

    Wow, 2 years old and still the best beginner python tutorial I could find. You obviously enjoy what you do, and it shows. Thanks for all your hard work.

  • Bishoy Zakaria
    Bishoy Zakaria 5 months ago

    There is a lot of info here, which is great but how do we use these tools to actually code. basically, how would we apply them?

  • arpita behura
    arpita behura 5 months ago +1

    I must say excellent stuff packed in a video. Awesome Corey!!!

  • Michelle Mouton
    Michelle Mouton 5 months ago

    What are you pressing to comment out and uncomment so many lines at once 🤩

    • Corey Schafer
      Corey Schafer  5 months ago

      That’s a keyboard shortcut in Sublime. “Cmd + /“ for Mac and “Carl + /“ for Windows. I made a video that covers my favorite features and shortcuts in Sublime. You can find that video for your operating system here:

  • rancidsox888
    rancidsox888 5 months ago +1

    Do you have any relevant practice exercises (or reccomendations) that follow the pace/content of your videos? I'm learning so much and would love to have exercises to practice!

    • Issac Wiggins
      Issac Wiggins Month ago

      Honestly, the way I have been learning what I know now which is just the basic syntax is by googling python exercises and seeing if I can't figure them out. I been able to do some but a lot are far to advanced for me.

  • mohamed subhi bouchi
    mohamed subhi bouchi 5 months ago

    can I convert types ? for example converting set into list or converting tuple into set

  • Arun Thayaleveedu
    Arun Thayaleveedu 5 months ago +1

    Thanks Corey …….

  • Mahfuz Raihan
    Mahfuz Raihan 5 months ago +2

    Thank you so much for this. everything I clear about list exactly what I wanted.