Created
December 11, 2011 19:16
-
-
Save dketov/1462203 to your computer and use it in GitHub Desktop.
Вещественные и комплексные числа
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Неявное преобразование целых в вещественные | |
""" | |
a = 3 # name created | |
b = 4 | |
print 2 + 4.0, 2.0 ** b # mixed-type conversions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Явное преобразование целых в вещественные | |
""" | |
a = 3 | |
b = 4 | |
print b / (2.0 + a) # same as (4 / (2.0 + 3)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Комплексные числа | |
""" | |
#Complex numbers with a nonzero real component are written as "(real+imagj)", | |
#or can be created with the "complex(real, imag)" function. | |
print 1j * 1J | |
print 1j * complex(0,1) | |
print 3+1j*3 | |
print (3+1j)*3 | |
print (1+2j)/(1+1j) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Конвертация комплексных в вещественные | |
""" | |
#The conversion functions to floating point and integer | |
#(float(), int() and long()) don't work for complex numbers | |
a=3.0+4.0j | |
print a.real | |
print a.imag | |
print abs(a) # sqrt(a.real**2 + a.imag**2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment