Python complex attribute and method operation example, python Complex

Source: Internet
Author: User
Tags cplex

Python complex attribute and method operation example, python Complex

This example describes the Python complex attributes and operation methods. We will share this with you for your reference. The details are as follows:

# Coding = utf8''' the plural number is composed of a real number and a virtual number combination, which is expressed as: x + yj when a negative number is a pair of ordered floating point numbers (x, y ), x is the real part, and y is the virtual part. Negative Concepts in Python: 1. Virtual numbers cannot exist independently, they always form a complex number together with a real number with a value of 0.0. 2. The complex number consists of the real number and the virtual number. 3. The syntax that represents the virtual number: real + imagej4, real number, and virtual number are both floating point numbers. 5. The virtual number must have the built-in attributes of the suffix j or J: the complex object has the data attributes, which are the real and virtual parts of the complex. The complex number also has the conjugate method. You can call this method to return the complex number's compound number object. Complex attributes: real (real part of a Complex number), imag (Virtual part of a Complex number), conjugate () (return the Complex number of the total number of values) ''' class Complex (object ): ''''' creates a static attribute to record the class version number ''' version = 1.0 ''' and creates multiple complex classes, used to operate and initialize the plural ''' def _ init _ (self, rel = 15, img = 15j): self. realPart = rel self. imagPart = img # create the plural def creatComplex (self): return self. realPart + self. imagPart # obtain the imaginary part def getImg (self) of the input number: # convert the imaginary part to the string img = str (self. imagPart) # segment the string to obtain the number part img = img [:-1] return float (img) def test (): print "run test ........... "com = Complex () Cplex = com. creatComplex () if Cplex. imag = com. getImg (): print com. getImg () else: pass if Cplex. real = com. realPart: print com. realPart else: pass # original plural print "the religion complex is:", Cplex # obtain the bounded plural print "the conjugate complex is:", Cplex. conjugate () if _ name __= = "_ main _": test ()

Calculation Result:

PS: Here are some recommended computing tools for your reference:

Calculation tool for online mona1 functions (equations:
Http://tools.jb51.net/jisuanqi/equ_jisuanqi

Scientific calculator online use _ advanced calculator online computing:
Http://tools.jb51.net/jisuanqi/jsqkexue

Online calculator _ standard calculator:
Http://tools.jb51.net/jisuanqi/jsq

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.