Does it really print the repr, assuming we’re talking about the __repr__
method of its class instantiation? I could have sworn it printed the __str__
and had to double check.

Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC
v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information

>>> class MyClass(object):
...   def __repr__(self):
...     return "My __repr__"
...   def __str__(self):
...     return "My __str__"
...
>>> print(MyClass)
<class '__main__.MyClass'>
>>> print(MyClass())
My __str__
>>> print(repr(MyClass()))
My __repr__
>>>

​

On 22 September 2017 at 06:59, Justin Israel <[email protected]> wrote:

>
>
> On Fri, Sep 22, 2017 at 4:24 PM Simon Anderson <[email protected]>
> wrote:
>
>> That is correct. From my understanding, print will query each objects
>> _repr_ which it stores in a tuple and then prints that tuple out.
>> The reason why the single value is not a tuple, is that you cannot create
>> a tuple with one value.
>>
>> ie variableA = (), or variableA = (1) should both fail
>> if you want to create a tuple with only one value you have to write
>> variableA = (1,)
>>
>
> The print statement (python 2.x) does not create a tuple. It is printing
> the repr of whatever you give it.
>
> The syntax being used is actually creating a tuple:
> tup = (1,)
>
>
>>
>> On Friday, 22 September 2017 13:27:19 UTC+10, jettam wrote:
>>>
>>> I have a question about adding a comma to the end of a these print
>>> statements.   In the first example  ( print (Blah))  with out the
>>> comma, it prints the string?   and in the second example where I added the
>>> comma ( print (Blah,) ) It turns it into a tuple?   Is my observation
>>> correct here?
>>>
>>> Blah = "the comma changes it into, a tuple!?"
>>> print (Blah)
>>> # result: the comma changes it into, a tuple!?
>>>
>>>
>>> Blah = "the comma changes it into, a tuple!?"
>>> print (Blah,)
>>> # result: ('the comma changes it into, a tuple!?',)
>>>
>>>
>>> --
>> You received this message because you are subscribed to the Google Groups
>> "Python Programming for Autodesk Maya" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit https://groups.google.com/d/
>> msgid/python_inside_maya/2a74e97c-21f1-4fed-a2fc-
>> 42b2d54d06fb%40googlegroups.com
>> <https://groups.google.com/d/msgid/python_inside_maya/2a74e97c-21f1-4fed-a2fc-42b2d54d06fb%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/python_inside_maya/CAPGFgA2sDjkEeOjoDW6F8ksAGUepC
> UxDsZhsi5q1JfJ9Ypbe6Q%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2sDjkEeOjoDW6F8ksAGUepCUxDsZhsi5q1JfJ9Ypbe6Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOA88QZi16%2Bo-kA9GoDfjZFstQTBJpPuU%2B--6p8Oetrx1A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to