Created
September 19, 2019 14:17
-
-
Save techstackmedia/494a3625877009c0242cadf0c76545a7 to your computer and use it in GitHub Desktop.
This file contains 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
# Complex function conversion | |
# A different data type can be converted to a complex number | |
# Conversion of integer numbers to a complex number | |
# You can provide an argument to a complex() function | |
z = complex(10, 20) | |
print(z) | |
# (10+20j) | |
complex('10', '20') | |
# Traceback (most recent call last): | |
# File "<pyshell#3>", line 1, in <module> | |
# complex('10', '20') | |
# TypeError: complex() can't take second arg if first is a string | |
print(complex('10')) | |
# (10 + 0j) | |
# Conversion of boolean values to a complex number | |
# You cn provide an argument to the complex() function | |
z = complex(True, True) | |
print(z) | |
# (1+1j) | |
>>> z = complex(True) | |
>>> z | |
(1+0j) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment