What are Sets in Python? Python Tutorial for Absolute Beginners | Mosh
Skills:
Python for Data70%
Key Takeaways
This video tutorial by Programming with Mosh covers the basics of sets in Python, including creating sets, adding and removing items, and performing mathematical operations such as union, intersection, and difference. The tutorial also discusses the characteristics of sets, including their unordered nature and the inability to access items by index.
Full Transcript
in Python we have another very useful data structure called a set which is basically a collection with no duplicates so let's say we have a list of numbers with a bunch of duplicate items like this if you want to remove the duplicates we can convert this list to a set so I'm gonna define a variable UNIX we call the set function and pass the numbers list now when we print this take a look you only have unique items so one is not repeated also note that we use curly braces to define sets so here we can define a second set using curly braces with two items one and fourth now similar to lists we can add new items to a set or remove an existing one so here we can call second that add we can append a new number here we can also call remove and we can use the Len function to get the number of items in a set so these are the basics but we're set shine are in the powerful mathematical operations that are supported by them let me show you so I'm going to delete these three lines these are pretty basic and renamed UNIX to first so we have two sets first and second now we can get a union of two sets using the vertical bar so this expression will return a new set that includes all the items that are either in the first or in the second set let me show you so print actually I'm gonna change this four to five so now when we run this code you can see the union of these two sets is another set that includes all the items that are either in the first set or the second set we can also get the intersection of two sets so print first and second this will return a new set that includes all the items that are in both first and second sets take a look so the only number that exists in both these sets is one we can also get the difference between two sets so print first - second when we run this code we get two three four so the first set has these additional numbers that we don't have in the second set and finally we have symmetric difference so print first carrot second this will return the items that are either in the first or second sets but not both so let's run this we get two three four five now one thing you need to know about sets is that unlike lists they're unordered collection which means the items that we have in a set are not in sequence so we cannot access them using an index in other words if we try to print 1st of 0 we will get a runtime error set object does not support indexing so if you need to access items by an index you need to use a list we'd set quite often we use one of these operations here or we can check for the existence of an item in a set so we can check to see if one is in the first set then we can print yes there you go so to recap set is an unordered collection of unique items we cannot have duplicates and these objects are unordered they are not in sequence so we cannot access them using an index hi guys thank you for watching this tutorial my name is Mohammad Ani and I have tons of tutorials like this for you on my channel so be sure to subscribe and also please like and share this video if you want to learn Python properly from scratch with depth I have a comprehensive python tutorial for you the link is below this video so click the link to get started thank you and have a fantastic day
Original Description
What are sets in Python? How to use sets in Python? This Python tutorial explains it.
🔥Subscribe for more Python tutorials like this: https://www.youtube.com/channel/UCWv7vMbMWH4-V0ZXdmDpPBA?sub_confirmation=1
🔥Python for Beginners Tutorial: https://youtu.be/yE9v9rt6ziw
Python Exercises for Beginners:
https://programmingwithmosh.com/python/python-exercises-and-questions-for-beginners/
Python Cheat Sheet:
https://programmingwithmosh.com/python/python-3-cheat-sheet/
Want to learn more from me? Check out my blog and courses:
http://programmingwithmosh.com
https://www.facebook.com/programmingwithmosh/
https://twitter.com/moshhamedani
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Programming with Mosh · Programming with Mosh · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
6 Visual Studio Tips to Increase Your Productivity | Mosh
Programming with Mosh
Visual Studio Keyboard Shortcuts that Speed Up Debugging Applications | Mosh
Programming with Mosh
Backbone.js Tutorial Part 2 - Backbone.js Models: Working with Model Attributes
Programming with Mosh
Backbone.js Tutorial Part 3 - Backbone.js Models: Model Validation
Programming with Mosh
Backbone.js Tutorial Part 4 - Backbone.js Models: Model Inheritance
Programming with Mosh
Backbone.js Tutorial Part 1 - Backbone.js Models: Creating Models
Programming with Mosh
Backbone.js Tutorial Part 5 - Backbone.js Models: Syncing Models with the Server
Programming with Mosh
Backbone.js Tutorial Part 6 - Backbone.js Collections: Creating Collections
Programming with Mosh
Backbone.js Tutorial Part 7 - Backbone.js Collections: Working with Collections
Programming with Mosh
Backbone.js Tutorial Part 8 - Backbone.js Collections: Fetching Collections from the Server
Programming with Mosh
Backbone.js Tutorial Part 9 - Backbone.js Views: Creating Views
Programming with Mosh
Backbone.js Tutorial Part 10 - Backbone.js Views: Passing Data to Views
Programming with Mosh
Backbone.js Tutorial Part 11 - Backbone.js Views: Handling the DOM Events
Programming with Mosh
Backbone.js Tutorial Part 12 - Backbone.js Views: Handling the Model Events
Programming with Mosh
Backbone.js Tutorial Part 13 - Backbone.js Views: Handling Collection Events
Programming with Mosh
Backbone.js Tutorial Part 14 - Backbone.js Views: Templating
Programming with Mosh
Clean Code: Learn to write clean, maintainable and robust code
Programming with Mosh
C# Events and Delegates Made Simple | Mosh
Programming with Mosh
C# Generics Tutorial: Whats and Whys | Mosh
Programming with Mosh
Debugging C# Code in Visual Studio | Mosh
Programming with Mosh
Repository Pattern with C# and Entity Framework, Done Right | Mosh
Programming with Mosh
Angular 2 Tutorial for Beginners: Learn Angular 2 from Scratch | Mosh
Programming with Mosh
Architecture of Angular 2+ Apps
Programming with Mosh
Working with Components in Angular
Programming with Mosh
C# Tutorial For Beginners - Learn C# Basics in 1 Hour
Programming with Mosh
Difference between Junior and Senior Developers
Programming with Mosh
Step-by-step ASP.NET MVC Tutorial for Beginners | Mosh
Programming with Mosh
[Pluralsight]: Become a Full-stack .NET Developer
Programming with Mosh
Xamarin Forms Tutorial: Build Native Mobile Apps with C#
Programming with Mosh
Value Types and Reference Types in JavaScript
Programming with Mosh
Using Redux in Angular 2+ Apps | Mosh
Programming with Mosh
Testing Angular 2+ Apps with Jasmine and Karma | Mosh
Programming with Mosh
Profile and optimize your Angular 2 apps
Programming with Mosh
Build a Real-world App with ASP.NET Core and Angular 2
Programming with Mosh
Entity Framework 6 Tutorial: Learn Entity Framework 6 from Scratch
Programming with Mosh
Two-way Binding and ngModel in Angular 4
Programming with Mosh
Udemy Live 2017: Teaching Tech Panel
Programming with Mosh
Demo of An E-commerce App Built with Angular, Firebase and Bootstrap 4
Programming with Mosh
My Brand New Angular Course
Programming with Mosh
TypeScript Tutorial - TypeScript for React - Learn TypeScript
Programming with Mosh
Access Modifiers in TypeScript
Programming with Mosh
TypeScript Interfaces
Programming with Mosh
TypeScript Classes
Programming with Mosh
TypeScript Constructors
Programming with Mosh
TypeScript Properties
Programming with Mosh
Angular Tutorial for Beginners: Learn Angular & TypeScript
Programming with Mosh
AngularJS vs Angular 2 vs Angular 4 | Mosh
Programming with Mosh
Angular Material Tutorial | Mosh
Programming with Mosh
Angular Animations Tutorial | Mosh
Programming with Mosh
Firebase in Angular Applications | Mosh
Programming with Mosh
Deploying Angular Applications | Mosh
Programming with Mosh
Building Forms in Angular Apps | Mosh
Programming with Mosh
Directives in Angular Applications
Programming with Mosh
Routing and Navigation in Angular | Mosh
Programming with Mosh
Angular 4 in 40 Minutes
Programming with Mosh
[NEW COURSE] Unit Testing for C# Developers
Programming with Mosh
Unit Testing C# Code - Tutorial for Beginners
Programming with Mosh
C# Classes Tutorial | Mosh
Programming with Mosh
C# Object Initializers Tutorial
Programming with Mosh
C# Constructors Tutorial | Mosh
Programming with Mosh
More on: Python for Data
View skill →
🎓
Tutor Explanation
DeepCamp AI