3 ms·
What's the issue? I don't know Python,are these features uncommon?
by weatherlight 3y ago
What's the issue? I don't know Python,are these features uncommon?
- stop50 3y agoThe first block are formatstrings, i don't recognize the third example. the second is an generic function. I don't recognize the third and the fourth is an obscure list manipulation, usually used to lengthen a list. im completly lost at the 5th and 6, but number seven takes specific values from an list/tuple and throws away the rest.
- abdullahkhalids 3y agoHard to follow your comment. String formatting. var: str = "Haha" print(f"{var:_>20}") print(f"{var:*^20}") print(f"{str.lower() = }") A function declaration with variable types declared. def concatenate[T: (str, bytes)](first: T, second: T) -> T: return first + second Should be written like items[:] = []. Here items[:], which is equivalent to items[0:3], is being set to an empty list. items = [1, 2, 3] items [:]=[] Extend the list 0 times. So items = [] after this. items *= 2 will create items = [1,2,3,1,2,3]. items = [1, 2, 3] items *=0 Again, not typical spacing used. drink, = bowl only works if bowl is a list/tuple/etc with only one item. Assigns first element of bowl to drink. Usually written as drink = bowl[0]. bowl = ['water'] drink ,= bowl # is a comment symbol in python, so ignore all stuff after it. n*['.'] creates ['.', '.', '.']. If we only had ['a', 'b', 'c', n*['.']] (no * before n), then we create ['a', 'b', 'c', ['.', '.', '.']]. The * before n unpacks the inner list so we create ['a', 'b', 'c', '.', '.', '.']. n = 3 ['a', 'b', 'c', *n* ['.']] #> ['a', 'b', 'c', '.', '.', '.'] This just assigns a = 1 and assigns _ = (2,3). *_ is syntax for "rest of the list/tuple/sequence/etc". a, \*_ = (1,2,3)