Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Unpacking With the Asterisk Operators

Comments & Discussion

*a, = "RealPython"

a with a trailing comma seems to be a list type, not a tuple

zuckerjohn on Jan. 23, 2020

Good observation ‘GJ’, I think you are right.

Here to demonstrate.

>>> a = [Python, bytes]
>>> type(a) 
<class list> 
>>> b, = Python, bytes 
>>> type(b) 
<class list> 
>>> a == b 
True 
>>> a == tuple(b) 
False

There may be some transferred confusion from a comma idiosyncracy as follows

>>> type((singleterm,))
<class tuple> 
>>> type((singleterm)) 
<class str>

Karan Khosla on Feb. 26, 2020

def sum(*args): # Returns a tuple values

Whereas,

my_list = [1, 2, 3, 4, 5] 
a, *b, c = my_list 

Here, *b returns a list not a tuple? What am missing here. Please help.

Cristian Palau on May 8, 2020

Thanks for the course!

Become a Member to join the conversation.