2

In Python

print(10 .__add__("1"))

The output comes as :

-NotImplemented 

Why this as in just this, no error no exception

vaultah
  • 44,105
  • 12
  • 114
  • 143
  • 3
    ["If one of those methods does not support the operation with the supplied arguments, it should return NotImplemented"](https://docs.python.org/3/reference/datamodel.html#object.__add__) – vaultah Jun 21 '15 at 11:57
  • 1
    possible duplicate of [Python NotImplemented constant](http://stackoverflow.com/questions/1062096/python-notimplemented-constant) – Mazdak Jun 21 '15 at 12:07
  • 1
    I think this is a bit different - you need the space between `10` and `.__add__('1')` or you just get an invalid syntax error. Some oddity in the CPython implementation? – Eric Appelt Jun 21 '15 at 12:10
  • Oh, no - everyone is right - you just need the space to distinguish a decimal point from getting the attribute in the case of a string literal, so it looks odd. You can't add a string to an int - so it is NotImplemented duplicate. – Eric Appelt Jun 21 '15 at 12:18
  • I have put the space there, guess it's not visible. – Aakansha Vatsa Jun 21 '15 at 14:39

1 Answers1

0
print(10 .__add__("1"))

the ("1") specifies the string,since it is enclosed in a double quotes..

10 indicates integer....

the function to add string and integer is probably may not be implemented earlier..so this is why python shows NotImplemented

print(10 .__add__(1)) 

and the space also doesn't matter..!!!!

print((10).__add__(1))

the above two codes also will work