.


:




:

































 

 

 

 





.

>>> 11 / 2 ①
5.5
>>> 11 // 2 ②
5
>>> −11 // 2 ③
−6
>>> 11.0 // 2 ④
5.0
>>> 11 ** 2 ⑤
121
>>> 11 % 2 ⑥
1

/ . float, , , int.
// . , , ( ) , .
, // . , , . . −6 −5; , , −5.
// . float, , float.
** . 112 121.
% . 11, 2, 5 1 , 1.

 

Python 2, / , . Python 3, / . . PEP 238.

Python . , .

>>> import fractions ①
>>> x = fractions.Fraction(1, 3) ②
>>> x
Fraction(1, 3)
>>> x * 2 ③
Fraction(2, 3)
>>> fractions.Fraction(6, 4) ④
Fraction(3, 2)
>>> fractions.Fraction(0, 0) ⑤
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "fractions.py", line 96, in __new__
raise ZeroDivisionError('Fraction(%s, 0)' % numerator)
ZeroDivisionError: Fraction(0, 0)

:

( ):

"<stdin>", 1, <>

"fractions.py", 96, __new__

raise ZeroDivisionError('(%s, 0)' % )

ZeroDivisionError: (0, 0)

, fractions.
, Fraction .
. Fraction.
Fraction .
Python , .

Python .

>>> import math
>>> math.pi ①
3.1415926535897931
>>> math.sin(math.pi / 2) ②
1.0
>>> math.tan(math.pi / 4) ③
0.99999999999999989

math π .
math , sin(), cos(), tan(), asin().
, , Python . 1.0, 0.99999999999999989.




:


: 2016-11-18; !; : 642 |


:

:

,
==> ...

1543 - | 1519 -


© 2015-2024 lektsii.org - -

: 0.009 .