Write a Python program to check whether an instance is complex or not
- برمجة
- برمجة بايثون
- 2021-04-15
- salsabeelalhams99111801528
الأجوبة
import json
def encode_complex(object):
# check using isinstance method
if isinstance(object, complex):
return [object.real, object.imag]
# raised error if object is not complex
raise TypeError(repr(object) + " is not JSON serialized")
complex_obj = json.dumps(2 + 3j, default=encode_complex)
print(complex_obj) أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال