Self-developed artificial intelligence ------ variable understanding and operations in Python,

Source: Internet
Author: User

Self-developed artificial intelligence ------ variable understanding and operations in Python,

Today, I will introduce the Number variable in python, which is somewhat different from c ++ and java. Let's introduce it to you as follows:

In python, you do not need to declare the variable type, but you need to assign a value to the variable before using it. It is meaningless to have no variable worth it, and the compiler will not pass

I. Integer ----- int:

The usage of int in python is roughly the same as that in c ++:

A = 12

Print

The printed result is: 12.

Here I will first introduce several functions

Type (): return the Data type in parentheses.

A = 'hello'

Print type ()

>>>> <Type 'string'>

 

Len (): returns the length of the variable in parentheses.

Note: The len () method cannot be of the int type.

A = 'Hello world'

Print len ()

>>> 11

Ii. Floating Point ------ float

Float is composed of integer and decimal parts. It can also be expressed by scientific notation.

A = 1.23

Print type ()

>>< Type 'float'>

 

Iii. Plural

The plural part is composed of the real number and the virtual number. a + bj or comple (a, B) can be used. The real part a and the virtual Part B of the plural are float.

 

Iv. Data Type Conversion

Int (x): converts x to an integer.

Float (x): converts x to a floating point number.

Complex (x): converts x to a plural number. The real part is x, and the virtual part is 0.

A = 1.23

Print complex ()

>>> (1.23 + 0j)

Complex (x, y): converts x and y into a plural number. The real number is x, and x and y are numeric expressions.

 

5. Constants

Python has two common constants, PI and E.

PI: mathematical constant pi (circumference rate)

E: mathematical constant e. It is a natural number.

 

Now, today's introduction is over, hoping to help you.

 

 

 

 

 

 

 

 

 

 

 

 

Related Article

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.