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
@BaloWest4 жыл бұрын
This video have me a serious eureka moment about tuples. Did have to watch it twice, but I got there!
@akbarrauf27417 жыл бұрын
thank you ,mit
@wah704 Жыл бұрын
That handwriting 💀💀
@lecirconflex5 жыл бұрын
- 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.
@bakedbeings5 жыл бұрын
I think a markdown -> html convertor with language based hilighting is a great way to make lecture notes for coding these days.
@bee_irl4 жыл бұрын
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.
@lecirconflex4 жыл бұрын
@@bee_irl You're missing the point.
@bakedbeings5 жыл бұрын
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-dh3lh2 жыл бұрын
Had fun!! Thanks teacher!!
@taoyan15234 жыл бұрын
How do you know that first is a string instead of a tuple? Because it doesn't have parentheses?
@carmenc72514 жыл бұрын
she mentioned abt it that if it has no comma in the bracket then it's a string
@lindgren.bjorn14 жыл бұрын
Yes, I guess for first to be a tuple it would need to be something like first = (t1[0], t2[0])
@bobanmilisavljevic785711 ай бұрын
Because of the comma after the string. Without the comma it's just a string
@chongke62157 жыл бұрын
In your case, t1 = ('cloud'), t2 = ('cold'), they are both tuples, so the answer shouldn't be ('sunny','cloudcold')?
@tommypham58747 жыл бұрын
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")
@intuit136 жыл бұрын
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).
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.
@augustocarrillo59272 жыл бұрын
estaba buena la teacher
@H3000-v7i7 жыл бұрын
The hand writing is worse than a six-year-old.
@vincentdsouza87116 жыл бұрын
She's actually using a stylus as touch input on the screen