Self-hing Artificial intelligence------The variable cognition and operation of Python language

Source: Internet
Author: User
Tags mathematical constants

Today, I would like to introduce you to the number variable in Python, which is somewhat different from C++,java, let's introduce:

It is not necessary to declare a variable type in Python, but it is not worthwhile to assign a value to a variable before it is used, and the compiler will not pass

One: integer-----int:

The use of int in Python is roughly the same as C + +:

A=12

Print a

The result of the printing is: 12

Here I would like to first introduce you to a few functions

Type (): Returns the data type in parentheses

A= ' Hello '

Print type (a)

>>>><type ' String ' >

Len (): Returns the length of the variable in parentheses

Note: Using the Len () method is not possible with the int type

A= ' Hello World '

Print Len (a)

>> >11

Two: Float type------float

Floating-point types consist of integers and fractional parts, or they can be represented by scientific notation

a=1.23

Print type (a)

>> <type ' float ' >

Three: plural

Complex numbers are composed of real and imaginary parts, which can be a+bj or comple (A, B), and the real and imaginary parts of the complex numbers are floating point types

Four: Data type conversions

int (x): Converts x to an integer

Float (x): Converts x to a floating-point number

Complex (x): Converts x into a complex number, the real part is x, and the imaginary part is divided into 0

a=1.23

Print Complex (a)

>>> (1.23+0J)

Complex (x, y): Converts x and y to a complex number, the real part is divided into x,x and y is a numeric expression

V: constant

There are two more common constants in Python, Pi and E

Pi: Mathematical constant Pi (π)

E: Mathematical constants E. i.e. Natural number

Well, today's presentation is over and I hope to help you.

Self-hing Artificial intelligence------The variable cognition and operation of Python language

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.