Skip to playerSkip to main contentSkip to footer
  • 5/18/2025
A tuple in Python is an ordered, immutable sequence of elements. Tuples are defined by enclosing a comma-separated sequence of elements within parentheses (). Unlike lists, tuples cannot be modified after creation, meaning elements cannot be added, removed, or changed.

Category

📚
Learning
Transcript
00:00Hello, welcome back.
00:05Now we will talk about a new data structure.
00:10I remember that in the last lecture,
00:13we talked about the item method
00:16in the dictionary object.
00:19I want to call my word name.
00:21I want to call the item method in the dictionary object.
00:25This is the player name, powerful.
00:28Now, every key value pair
00:32is in round brackets.
00:35This is a list,
00:37but the list is in round brackets.
00:40Then, every element,
00:42the key value pair,
00:44is separated.
00:46This round bracket is basically
00:49a representation of a tuple.
00:52Tuple, by its very definition,
00:56immutable,
00:57and the list,
00:59there is only one change.
01:01The list is mutable.
01:03Tuple is immutable.
01:05Define is round brackets.
01:07The element is comma.
01:09Now, if I say,
01:11one comma two comma three,
01:14and this is test,
01:17underscore tuple.
01:19Tuple,
01:20tuple,
01:21tuple,
01:22tuple,
01:23tuple,
01:24tuple,
01:25tuple,
01:26tuple,
01:27and,
01:29and,
01:30kaboom,
01:31shaka,
01:32laaka,
01:33one, two, three,
01:34this is print.
01:35I remove it.
01:36This is example for me.
01:38Okay.
01:39So,
01:40now,
01:41by its very definition,
01:44I have to say,
01:45this immutable is immutable.
01:48Immutable is.
01:49This way,
01:50this string immutable is immutable.
01:53Now,
01:54let's check on our hypothesis,
01:56whether it's okay or not.
01:58First of all,
01:59we check on indexing.
02:01Is it not?
02:02Is it ordered?
02:03Is it not?
02:04Let's go.
02:05No problem.
02:06I say,
02:07zero,
02:08which element is added?
02:10Zero,
02:11which element is added?
02:12I tell you,
02:13which element is added.
02:14I tell you,
02:15which element is added.
02:16I tell you,
02:17which element is added.
02:18I tell you,
02:19which element is added.
02:20The element is added.
02:21This is the ordered sequence of elements
02:29or objects.
02:30You can confirm that.
02:32I said,
02:34which is the list of twoples of elements,
02:38you can do it.
02:39You,
02:40because it is immutable,
02:42you can also only re-assign.
02:45You can do it.
02:48I tell you,
02:50one پڑھا ہوئے میں نے کہا یار ٹھیک ہے یہ تو
02:52تم نے بہت ہی اندہ کام کیا
02:53یار اس طرح کر سکتے ہو یہ تھوڑے
02:56اسے پیسے لے لو اور جو one پڑھا ہوئے
02:58نا اس کو 10 سے replace کر دو
02:59ایسا کر سکتے ہو تم
03:01کر کے دیکھتے ہیں جی میں اس کو execute
03:04کرتا ہوں اور
03:05کبوم شاکہ
03:06لاکہ وہ کہتا ہے کہ نہیں
03:09I cannot do this
03:11اس کی reason یہ ہے کہ double by its
03:13very definition immutable ہوتا ہے
03:15ایک تو
03:17concept clear ہو گیا
03:18دوسرا important concept ہے
03:20tuple unpacking کا
03:22اب جس طرح ہم ایک dictionary کو
03:27unpack کرتے تھے اسی طرح ہم tuple کو
03:29unpack کر سکتے ہیں مثال کے طور پر اس کے اندر تین
03:31elements ہیں ایسا ہی ہے نا تو میں کہہ سکتا ہوں
03:33a, b, c
03:36is equal to
03:37test tuple
03:38and here you go tuple unpack ہو گیا
03:41اگر آپ print کرائیں اس کو
03:43a کو یا پھر آپ
03:45print کرائیں b کو یا c کو
03:47you can easily get the values
03:48ٹھیک ہے یہ دیکھئے میں کہتا ہوں b
03:51and then of course
03:53آپ یہاں پہ کہہ سکتے ہیں
03:54ٹھیک ہے
03:55اس کی
03:55at the moment اس کو remove کرتے ہیں
03:57میں run کرتا ہوں
03:58here you get one two three
04:00اس کو کہتے ہیں
04:01tuple unpacking
04:03اب
04:04again میں reiterate کرتا ہوں
04:07جو چیزیں آپ نے list میں سکھی
04:08سارے کے ساری وہی کر سکتے ہیں
04:10however with minor change
04:12کیونکہ یہ immutable ہے
04:13آپ element کو change نہیں کر سکتے
04:15ایک اور important concept
04:18tuple کے اندر
04:19وہ یہ ہے
04:20کیونکہ یہ immutable ہے
04:21اور میں نے کہا تھا
04:22کہ dictionary کی کی جو ہے
04:24وہ ہمیشہ immutable رہے گی
04:26تو آپ simple یہاں پہ tuple کو رکھ سکتے ہیں
04:28however آپ کو یاد ہوگا
04:31کہ یہاں پہ ہم list نہیں رکھ سکتے تھے
04:33ایسا ہی ہے نا
04:34اگر میں یہاں پہ کہتا ہوں نا
04:35print
04:36ٹھیک ہے
04:37اور dictionary
04:39اور پھر dictionary کو میں
04:41کہہ دیتا ہوں
04:42کہ تمہر پاس dictionary جو ہے
04:45وہ ہے یہ tuple
04:46ٹھیک ہے
04:47اس tuple کے اوپر جو چیز پڑی ہوئی ہے
04:49وہ مجھے دکھاؤ
04:50ٹھیک ہے
04:51اب میں اس کو remove کر دیتا ہوں
04:52let's see if this works
04:54and name
04:57result آگیا
04:58it means it works
04:59اس کا مطلب یہ ہے کہ
05:01آپ
05:03keys کے اوپر کوئی بھی
05:04immutable data پر رکھ سکتے ہیں
05:06چاہے وہ string ہو
05:07number ہو
05:08boolean ہو
05:08tuple ہو
05:09mutable نہیں رکھ سکتے
05:11ٹھیک ہے
05:12excellent
05:13اس کے ساتھ
05:16of course
05:17آپ وہ سارے کام کر سکتے ہیں
05:19جو آپ نے list کے اوپر کیے
05:21مثال کے طور پر
05:22یہ دیکھئے
05:23ایک test tuple ہے
05:24میں اس کو remove کر دیتا ہوں
05:25اب یہ test tuple ہے آپ کے پاس
05:26one two three
05:27آپ یہاں پہ check کر سکتے ہیں
05:29کیا یہ let's say one exist کرتا ہے
05:32کہ نہیں کرتا
05:32جس طرح آپ
05:34باقی کرتے تھے
05:36کہ let's say
05:37one
05:37in
05:39test tuple
05:40ٹھیک ہے
05:42اور اس کو آپ print کر دیں
05:43اگر یہ آپ کو true return کرتا ہے
05:46تو اس کا مطلب یہ ہے
05:47کہ یہ statement correct ہے
05:48one exist کرتا ہے
05:49اگر نہیں تو پھر نہیں
05:50پھر false ہے
05:51and it does return true
05:53اگر میں یہاں پہ کہتا ہوں
05:54two hundred
05:55and execute this
05:58of course
05:59two hundred
06:00ہماری tuple
06:00کے اندر exist
06:01نہیں کرتا
06:02اب دو important methods ہیں
06:05جو کہ آپ
06:05tuple q پر call
06:06کر سکتے ہیں
06:07سب سے پہلا جو
06:08method ہے
06:09وہ ہے
06:09آپ کا
06:10count
06:11اور پھر دوسرا
06:12method ہے
06:13index
06:13اب
06:14مثال کے طور پہ
06:16یہ test tuple ہے
06:16میں اس کو تھوڑا سے
06:17increase کرنے لگوں
06:18میں کہتا ہوں
06:18four
06:19comma
06:20five
06:20comma
06:21six
06:21ٹھیک ہے
06:22comma
06:23seven
06:24comma
06:24eight
06:24comma
06:24nai
06:25ٹھیک ہے
06:26اچھا
06:27اب
06:28اگر میں
06:29simple
06:30اس
06:31test tuple
06:33کے
06:34اوپر
06:34test tuple
06:35کی
06:36دیکھنا چاہتا ہوں
06:37number of
06:38element
06:39کتنے ہیں
06:39تو میں اس کے اوپر
06:40length
06:40method
06:41call
06:41کر سکتا ہوں
06:42ٹھیک ہے
06:42اب ذرا دیکھئے
06:44میں اس کو
06:44execute
06:44کرتا ہوں
06:45یہ مجھے
06:45number of
06:45element
06:46بتائے گا
06:46اور یہی کام
06:47ہم کرتے تھے
06:47method
06:48جب
06:48call
06:48کرتے تھے
06:49اسی طرح
06:51میں اس کے اوپر
06:51dot count
06:52method
06:53call
06:53اور
06:53dot count
06:54کو
06:54اگر میں
06:54count
06:55کروانے
06:55ہیں
06:55specific element
06:57let's say
06:57یہ دیکھئے
06:57میں
06:58seven
06:58کو
06:59two
06:59time
06:59کرنے
06:59لگوں
07:00ٹھیک ہے
07:00یہ دیکھئے
07:00seven
07:01two
07:01time
07:01آرہا
07:01نا
07:01اب
07:02میں اس
07:02کو
07:02کہتا ہوں
07:02seven
07:03کتنی
07:03دفعہ
07:03آیا
07:04ہے
07:04count
07:05کر
07:05کے
07:05مجھے
07:05بتاؤ
07:05and
07:06it
07:06says
07:06two
07:07times
07:07ٹھیک ہے
07:08اور
07:09باقی
07:09اگر
07:09کوئی
07:09element
07:10دیتا
07:10ہوں
07:10let's
07:10say
07:10eight
07:10کیونکہ
07:11eight
07:11one
07:11time
07:11آیا
07:12ہے
07:12تو
07:12it
07:12will
07:13tell
07:13me
07:13one
07:13time
07:14اسی
07:15طرح
07:15ایک
07:15اور
07:15function
07:16ہے
07:16جو
07:16کہ
07:16index
07:17کا
07:18جس
07:18میں
07:19آپ
07:19index
07:20دیتے
07:21ہیں
07:21آپ
07:22کہتے ہیں
07:23index
07:24اور
07:24index
07:25پہ
07:25آپ
07:25کہتے ہیں
07:250
07:26کے
07:26اوپر
07:26کون
07:27سا
07:27element
07:28پڑھا
07:28ہے
07:28جو
07:28ہی
07:28آپ
07:29run
07:29کرتے
07:29ہیں
07:29اوکی
07:32تو
07:32ہم
07:32نے
07:32یہاں
07:33پہ
07:33ایک
07:33چھوٹی
07:33سی
07:33غلطی
07:34کی
07:34ہے
07:34basically
07:35یہ
07:35index
07:35return
07:36کرتا
07:36ہے
07:37index
07:37لیتا
07:37نہیں
07:38ہے
07:38my
07:38mistake
07:39guys
07:39my
07:39mistake
07:40یہ
07:40index
07:41return
07:41کرتا
07:42ہے
07:42sometimes
07:42my
07:43tongue
07:43slip
07:44تو
07:45یہاں
07:45پہ
07:46آپ
07:46نے
07:46غور
07:46کرنا
07:47ہے
07:47کہ
07:47ہم
07:47نے
07:47element
07:48دینا
07:48ہے
07:48جیسا
07:48count
07:49کو
07:49ہم
07:58ہوگا
07:58وہ
07:58یہاں
07:58پہ
07:59return
07:59کر
07:59دے
07:59گا
07:59یہ
08:007
08:00کی
08:00location
08:01position
08:01کون
08:01سے
08:01اور
08:02وہ
08:02ہے
08:026
08:02اسی
08:03طرح
08:03اگر
08:03let's
08:04میں
08:04کہتا
08:04ہوں
08:041
08:04اور
08:05اس
08:05کو
08:05execute
08:06کرتا
08:06ہوں
08:06تو
08:07یہ
08:11so
08:12far
08:13we
08:13have
08:13done
08:13we
08:14have
08:14covered
08:14a
08:15lot
08:15about
08:15tuples
08:16one
08:17of
08:17its
08:18application
08:18اب
08:19وہی
08:19بات
08:19میں
08:19دوبارہ
08:20reiterate
08:20کرتا
08:20ہوں
08:21جو
08:21کہ
08:21ہم
08:21نے
08:21کی
08:21تھی
08:21ایک
08:22fundamental
08:23چیز
08:23ہے
08:24کہ
08:24tuple
08:24اور
08:25list
08:26جب
08:26دونوں
08:26ایک ہی
08:27جیسی
08:27چیز
08:27ہیں
08:27ایک ہی
08:28جیسے
08:28function
08:28perform
08:29کرتی
08:29ہیں
08:29تو
08:30پھر
08:30tuple
08:30کی
08:30کہاں
08:31ضرورت
08:31پڑتی
08:31ہے
08:31دیکھیں
08:33آپ
08:33let's
08:33say
08:33ایک
08:34application
08:35بنا
08:35رہے ہیں
08:35bank
08:36کے
08:36لیے
08:36تو
08:37of
08:38course
08:38آپ
08:38کو
08:39کچھ
08:39اس
08:39طرح
08:40کا
08:40data
08:40structure
08:40چاہیے
08:41جس
08:41میں
08:41inherently
08:43یہ
08:43capability
08:44ہو
08:44کہ
08:44کوئی
08:44hacker
08:45اس
08:45کو
08:45change
08:45نہ
08:45کر
08:45سکے
08:46کیونکہ
08:46آپ
08:47چاہتے ہیں
08:47کہ
08:47کوئی
08:48ایسا
08:48نہیں
08:48نہ
08:48ہو
08:49کہ
08:49third
08:49party
08:49آیا
08:49اور
08:50کسی
08:50کے
08:50account
08:50کے
08:50پیسے
08:51add
08:51کر
08:51دے
08:51یا
08:52پیسے
08:52change
08:52کر
08:52دے
08:53وہ
08:54اگر
08:54list
08:54کریں
08:55گے
08:59تو
09:00اس
09:00میں
09:00تو
09:00یہ
09:00possible
09:00ہے
09:01لیکن
09:01اگر
09:01tuple
09:01کریں
09:01اس
09:02میں
09:02یہ
09:02possible
09:03ہی
09:03نہیں
09:03ہے
09:03change
09:04کر
09:04نا
09:04تو
09:04آپ
09:05نے
09:05handling
09:05data
09:06structure
09:06ہی
09:06ایسا
09:06رکھا
09:07ہوا
09:07ہے
09:08کہ
09:08اس
09:08bank
09:09کو
09:09break
09:09کرنا
09:09آسان
09:10نہیں
09:10ہے
09:10ایک
09:11just
09:11example
09:11دے
09:12رہا ہوں
09:12ٹھیک ہے

Recommended