How can an int be '+' with a tuple?

Jach Fong jfong at ms4.hinet.net
Sun Jun 3 01:12:28 EDT 2018


After a quick check I got:

D:\Works\Python\PP4E-Examples-1.4\Examples\PP4E>py
Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 
bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> t = ('myname',)
 >>> n = (3,)
 >>> n + t
(3, 'myname')
 >>>

I may overlook Gary's reply. The "any" has not unpacked yet at that 
time:-) My fault, sorry.

----------------
Yes, (I think) I know the *any usage, but don't know their type will be
changed after unpack?


Gary Herron 於 2018/6/3 下午 12:05 寫道:
> In fact, the value of *any* is *not* an integer.  The *any notation 
> causes Python to pack all the arguments into a tuple. This feature is 
> usually used when there are multiple (and an unknown number) of 
> parameters, but it works perfectly well with a single parameter.
> 
> Here's an example:
> 
>  >>> def progress(*any):
>      print(any)
> 
>  >>> progress(1)
> (1,)
>  >>> progress(1,2,3)
> (1, 2, 3)
>  >>>
> 
> 
> On 06/02/2018 07:55 PM, jfong at ms4.hinet.net wrote:
>> The attached is a script which can run under Python 3.4/Windows Vista
>> correctly. One thing make me puzzled is that the "any + context" at line
>> 18. The "any" was passed as an integer from line 43 and the "context"
>> was defined as a tuple at line 35. This concatenation works! how?
>>
>> Best Regards,
>> Jach Fong
>>
>>
>>
>>
>>
>> ---
>> This email has been checked for viruses by Avast antivirus software.
>> https://www.avast.com/antivirus
>>
>>
> 



More information about the Python-list mailing list