Welcome to the Monastery PerlMonks

### Re^4: solve cubic equations (Python)

by no_slogan (Deacon)
 on May 05, 2017 at 18:43 UTC ( #1189597=note: print w/replies, xml ) Need Help??

in reply to Re^3: solve cubic equations (Python)

Python variables aren't typed. The result type is determined by the value (in Perl, it's usually determined by the operator). Float-vs-int-division is one of the annoying unnecessary incompatibilities in python3.
```> python2.7 -c 'print(5/2)'
2
> python3.5 -c 'print(5/2)'
2.5

Replies are listed 'Best First'.
Re^5: solve cubic equations (Python)
by LanX (Sage) on May 05, 2017 at 18:47 UTC
I guess most people do, but I don't care for it. If I have an integer, I need to use // to divide, or it gets converted to a float. If I have a Fraction, I need to use /, or it gets converted to an integer. You say, "but // always produces an integer, that's so much easier." But I don't see why there has to be a special operator devoted to integers.
```>>> from fractions import Fraction
>>> x = Fraction(22,7)
>>> y = 3
>>> print(x,x/2,x//2)
22/7 11/7 1
>>> print(y,y/2,y//2)
3 1.5 1
> But I don't see why there has to be a special operator devoted to integers.

To be spotted easily?

Look your explanation was better than mine, you're far more experienced than me with python, nevertheless you didn't see the error in the code.

Wasn't explicit is better than implicit a python slogan?

Anyway I like the many operators in Perl, what's lacking is optional explicit typing, to tune inner loops.

Strangely the parser already allows typing, for many years yet.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1189597]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2023-06-04 20:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How often do you go to conferences?

Results (22 votes). Check out past polls.

Notices?