Skip to content

Instantly share code, notes, and snippets.

@dketov
Created December 11, 2011 19:16
Show Gist options
  • Save dketov/1462203 to your computer and use it in GitHub Desktop.
Save dketov/1462203 to your computer and use it in GitHub Desktop.
Вещественные и комплексные числа
# -*- encoding: utf-8 -*-
"""
Неявное преобразование целых в вещественные
"""
a = 3 # name created
b = 4
print 2 + 4.0, 2.0 ** b # mixed-type conversions
# -*- encoding: utf-8 -*-
"""
Явное преобразование целых в вещественные
"""
a = 3
b = 4
print b / (2.0 + a) # same as (4 / (2.0 + 3))
# -*- 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)
# -*- 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