Tuples

  Рет қаралды 59,733

MIT OpenCourseWare

MIT OpenCourseWare

Күн бұрын

Пікірлер: 27
@nashsok
@nashsok 2 жыл бұрын
Regarding the fact that trailing commas are required in tuples containing a single object, this is because in addition to defining tuple literals, parentheses can also be used in Python to group expressions. Combined with the fact that an expression can be used to assign a value within a tuple, the trailing comma is necessary in order to avoid semantic ambiguity. An example: x = (5 + 10) will assign an int with value of 15 to var x whereas x = (5 + 10,) will assign a tuple containing a single int with value of 15 to var x
@BaloWest
@BaloWest 4 жыл бұрын
This video have me a serious eureka moment about tuples. Did have to watch it twice, but I got there!
@akbarrauf2741
@akbarrauf2741 7 жыл бұрын
thank you ,mit
@wah704
@wah704 Жыл бұрын
That handwriting 💀💀
@lecirconflex
@lecirconflex 5 жыл бұрын
- Why is there no syntax highlighting? - Why is the code not using a monospaced font? - Why is there a linebreak WITHIN IN THE STRING? - Why are the tuples created inline with the function call? - What does the function name have to do with the weather? Why does this show superficial semantics, which then add to the example at all? Programming is hard enough as is. It looks to me like you're more interested in intimidating people for missing trailing commas in questionable syntactic sidecases, rather than passing excitement.
@bakedbeings
@bakedbeings 5 жыл бұрын
I think a markdown -> html convertor with language based hilighting is a great way to make lecture notes for coding these days.
@bee_irl
@bee_irl 4 жыл бұрын
It's a Google doc, which answers your first three questions. If you open these assignments on the website, it uses monospace font and has proper line breaks. True, she could have used a screenshot in the question, but if this is your biggest gripe with the lecture, you can't complain much.
@lecirconflex
@lecirconflex 4 жыл бұрын
@@bee_irl You're missing the point.
@bakedbeings
@bakedbeings 5 жыл бұрын
It feels like a trailing comma in a tuple literal declaration is a good candidate for a syntax error. I imagine there are uses for and history to the current handling, but I wonder what price is paid in bugs. C++ is full of this stuff due to its age and history, I’m hoping the relatively youthful Python 3.x has less :)
@AnmolKumar-dh3lh
@AnmolKumar-dh3lh 2 жыл бұрын
Had fun!! Thanks teacher!!
@taoyan1523
@taoyan1523 4 жыл бұрын
How do you know that first is a string instead of a tuple? Because it doesn't have parentheses?
@carmenc7251
@carmenc7251 4 жыл бұрын
she mentioned abt it that if it has no comma in the bracket then it's a string
@lindgren.bjorn1
@lindgren.bjorn1 4 жыл бұрын
Yes, I guess for first to be a tuple it would need to be something like first = (t1[0], t2[0])
@bobanmilisavljevic7857
@bobanmilisavljevic7857 11 ай бұрын
Because of the comma after the string. Without the comma it's just a string
@chongke6215
@chongke6215 7 жыл бұрын
In your case, t1 = ('cloud'), t2 = ('cold'), they are both tuples, so the answer shouldn't be ('sunny','cloudcold')?
@tommypham5874
@tommypham5874 7 жыл бұрын
t1 is not a tuple. Without the comma t1 = 'cloud' is a string as opposed to t2 = 'cold', which is a tuple denoted by the comma. Since t1 is a string, think of it as a single set of multiple characters and t2 as a set of two elements 'cold' and empty. The first element of a string is the first character whereas the first element of a tuple is the first entire element itself. So the method would evaluate to ("Sunny", "ccold")
@intuit13
@intuit13 6 жыл бұрын
I don't think that's true anymore. I don't think a single-element tuple needs the comma to "make" it a tuple any longer. I can't test this right now, but I was pretty sure this was one of the differences with 3.6 or 3.6.5 that I noticed while reading from a book that was using 3.5 (another being that dictionaries are no longer random-ordered, but instead are now insertion-ordered).
@intuit13
@intuit13 6 жыл бұрын
someone correct me if I'm wrong
@mqL49J
@mqL49J 6 жыл бұрын
Python 3.7.0: >>> type(('cloudy')) >>> type(('cold',))
@lecirconflex
@lecirconflex 5 жыл бұрын
If you look closely, you can see that the first one is t1 = ('cloud'). In Python, this makes this value a string, because there is no comma within the braces. This is similar to (1 + 2), which doesn't create a tuple either. The second one, t2, however, has a trailing comma ('cold',) - This creates a tuple. The tuples are created inline, therefore the braces are required to disambiguate the tuples from the parameters of the function call. However, the braces aren't even required to create a tuple. You could do t2 = 'cold', which would create a tuple (because of the comma). This means that the call is actually always_sunny('cloudy', ('cold', )). Therefore t1[0] gives you a c, but t2[0] gives you the whole string.
@augustocarrillo5927
@augustocarrillo5927 2 жыл бұрын
estaba buena la teacher
@H3000-v7i
@H3000-v7i 7 жыл бұрын
The hand writing is worse than a six-year-old.
@vincentdsouza8711
@vincentdsouza8711 6 жыл бұрын
She's actually using a stylus as touch input on the screen
@adarshkumbhar4848
@adarshkumbhar4848 2 жыл бұрын
Better than yours...
Simple Lists
2:49
MIT OpenCourseWare
Рет қаралды 32 М.
5. Tuples, Lists, Aliasing, Mutability, and Cloning
41:28
MIT OpenCourseWare
Рет қаралды 231 М.
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
Арыстанның айқасы, Тәуіржанның шайқасы!
25:51
QosLike / ҚосЛайк / Косылайық
Рет қаралды 699 М.
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 40 МЛН
3. String Manipulation, Guess and Check, Approximations, Bisection
45:02
MIT OpenCourseWare
Рет қаралды 383 М.
Python lists, sets, and tuples explained 🍍
15:06
Bro Code
Рет қаралды 333 М.
2024 MIT Integration Bee - Finals
1:09:25
MIT Integration Bee
Рет қаралды 742 М.
Lecture 15: Recursion
45:19
MIT OpenCourseWare
Рет қаралды 14 М.
Python Workshop - All The Keywords
19:49
Core Electronics
Рет қаралды 45 М.
Intro to Tuples in C# In 10 Minutes or Less
9:50
IAmTimCorey
Рет қаралды 42 М.
Programming with Math | The Lambda Calculus
21:48
Eyesomorphic
Рет қаралды 246 М.
Difference Between List, Tuple, Set and Dictionary in Python
11:57
Kindson The Tech Pro
Рет қаралды 158 М.
Europe's Missing Trillions
10:01
Bloomberg Originals
Рет қаралды 615 М.
4. Decomposition, Abstraction, and Functions
41:09
MIT OpenCourseWare
Рет қаралды 237 М.
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН