3 ms·
That's true, but actually using a literal as a object is forbidden by the syntax. Python 3.8.9 (default, Mar 30 2022, 13:51:16) [Clang 13.1.6 (clang-1
by lisper 4y ago
That's true, but actually using a literal as a object is forbidden by the syntax.
Python 3.8.9 (default, Mar 30 2022, 13:51:16)
[Clang 13.1.6 (clang-1316.0.21.2.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1.__abs__
File "<stdin>", line 1
1.__abs__
^
SyntaxError: invalid syntax
>>>
Ruby allows this:
irb(main):001:0> 1.2.to_s
=> "1.2"
I think that's weird.
- pjmlp 4y agoOnly because those are special methods only allowed to be directly called by the runtime, doesn't change that the language model is actuall OOP based. You could have used one of those that is allowed instead, example: >>> (3.2).is_integer() False The parentheses are needed due to parsing precendence. So here is your Ruby like example in Python.
- lisper 4y agoFair enough. I guess I should probably take another look at Ruby.
- deleted 4y ago[deleted]