text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
Harry let's again type in Gryffindor | 607.88 | 5.519 |
enter and voila we still see that Harry | 610.32 | 5.28 |
is from Gryffindor but what are we | 613.399 | 4.321 |
actually doing here what are we actually | 615.6 | 4.28 |
doing by returning this value well it | 617.72 | 5.119 |
turns out that what we've just done is | 619.88 | 5.959 |
used a tupple a tupple is another type | 622.839 | 6.361 |
of data in Python that's a collection of | 625.839 | 6.401 |
values X comma y or X comma y comma Z | 629.2 | 5.16 |
it's similar in spirit to a list in that | 632.24 | 4.92 |
sense but it's immutable it's not | 634.36 | 4.8 |
mutable now what does that mean a list | 637.16 | 3.52 |
as we've seen it before is a data | 639.16 | 3.4 |
structure in Python that you can change | 640.68 | 3.8 |
the values of you can go into bracket | 642.56 | 4 |
zero for the first location and change | 644.48 | 3.359 |
the value there you can go to bracket | 646.56 | 2.92 |
one bracket two bracket three and | 647.839 | 3.721 |
actually change the values in lists but | 649.48 | 4.039 |
if you have no intention of changing the | 651.56 | 3.719 |
values of variables and you want to | 653.519 | 4.361 |
return effectively multiple values you | 655.279 | 3.961 |
don't have to even return it as as a | 657.88 | 3.48 |
list you can return it as a tupple | 659.24 | 4.44 |
instead just by using a comma and it | 661.36 | 4.44 |
turns out we can make explicit that | 663.68 | 4.399 |
here's the white lie I'm not actually | 665.8 | 5.2 |
returning two values per se whenever you | 668.079 | 5.281 |
use a comma in this way on line nine | 671 | 5.04 |
you're actually returning one value | 673.36 | 5.52 |
which is a tupple inside of that tupple | 676.04 | 4.72 |
now are two values so it's similar in | 678.88 | 3.84 |
spirit to returning one list with two | 680.76 | 4.8 |
things here I'm returning one Tuple with | 682.72 | 4.52 |
two things and the mere fact that I've | 685.56 | 3.839 |
used a comma and nothing else tells | 687.24 | 3.599 |
python that I indeed want to return a | 689.399 | 3.481 |
tuple but there's more explicit syntax | 690.839 | 4.161 |
that we can use instead I can actually | 692.88 | 5.199 |
more verbosely put explicit parentheses | 695 | 5.56 |
around the values of this tupple just to | 698.079 | 4.521 |
make more clear to me to the reader that | 700.56 | 4.12 |
this isn't two values per se this is one | 702.6 | 4.2 |
value with two things inside of it and | 704.68 | 3.76 |
what I can actually do then too is I | 706.8 | 3.76 |
don't have to unpack this up here so to | 708.44 | 3.76 |
speak I can actually go up here and | 710.56 | 4.36 |
maybe give a more apt name like student | 712.2 | 5.48 |
and I can name the value or rather name | 714.92 | 4.28 |
the variable in which I'm storing the | 717.68 | 3.8 |
return value of get student as quote | 719.2 | 4.72 |
unquote student so maybe this is a | 721.48 | 4.12 |
little better design now because I'm | 723.92 | 4.2 |
sort of abstracting away what a student | 725.6 | 4.52 |
is it's implemented at the moment as a | 728.12 | 4.12 |
tupple with two values but at least now | 730.12 | 4.88 |
I have a variable called what I mean a | 732.24 | 5.039 |
student but there's going to be a catch | 735 | 4.399 |
on line three I still want to print out | 737.279 | 4.56 |
that Student's name and their house but | 739.399 | 4.281 |
I don't have a name variable anymore and | 741.839 | 3.281 |
I don't have a house and I also don't | 743.68 | 3.599 |
have a dictionary as was proposed | 745.12 | 5.56 |
earlier so I can't even go at those keys | 747.279 | 6.081 |
by name but what a tupple is it's very | 750.68 | 4.88 |
similar in spirit to a list but it is | 753.36 | 4.279 |
indeed just immutable and what I mean by | 755.56 | 4.16 |
that is I can still index into it | 757.639 | 4.961 |
numerically by saying student square | 759.72 | 5.919 |
bracket Z for the item in the first | 762.6 | 4.84 |
location in that tupple and then over | 765.639 | 3.481 |
here instead of house I can say student | 767.44 | 4.079 |
bracket one student bracket one is going | 769.12 | 4.48 |
to give me the second location in that | 771.519 | 3.641 |
tupple let me go ahead and clear my | 773.6 | 3.56 |
terminal window again run python of | 775.16 | 4.679 |
student. let's type in Harry let's type | 777.16 | 5.72 |
in Gryffindor enter and we still have | 779.839 | 5.68 |
some working code let me pause here now | 782.88 | 5.639 |
and see if there are any questions on | 785.519 | 6.32 |
this technique of returning a tupple and | 788.519 | 6.32 |
indexing into it in this way I guess | 791.839 | 5.161 |
what's a like a actual use case where | 794.839 | 5.481 |
you would use a tupple versus you know a | 797 | 5.16 |
list or something else that's similar | 800.32 | 3.199 |
it's a really good question when would | 802.16 | 3.4 |
you use a tuple versus a list when you | 803.519 | 4.161 |
want to program defensively or in | 805.56 | 4.279 |
general when you know the values in this | 807.68 | 4.12 |
variable shouldn't change so why would | 809.839 | 3.721 |
you use a data type that allows them to | 811.8 | 4.64 |
be changed it just invites mistakes bugs | 813.56 | 4.92 |
down the line either by you or | 816.44 | 3.6 |
colleagues who are interacting with your | 818.48 | 4.039 |
code so tupple is just another way where | 820.04 | 4.799 |
you can increase the probability of | 822.519 | 4.281 |
correctness by just not letting anyone | 824.839 | 4.281 |
yourself included change the contents | 826.8 | 4.399 |
therein so it's just another tool in | 829.12 | 4.519 |
your toolkit but let's make clear then | 831.199 | 4.681 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.