Self-hing Artificial Intelligence---Understanding the basic data types and operations of the Python language

Source: Internet
Author: User

In the Python language, understanding the basic data types is essential, and today I'll show you a few basic data types:

A Integral type

int is often referred to as an integral or integer, and is used in Python as:

A=5

Print a

The printed result is 5, when a is expressed as an integer type

Two. Floating point Type

Float is represented as floating point, floating-point type consists of integral and fractional parts, or it can be represented by scientific notation:

a=3.14

Print a

The printed result is 3.14, when a is represented as a floating-point type

Three. Plural

The complex number is composed of real and imaginary parts, which can be represented by A+BJ or complex (a+b), and the real and imaginary part B of the complex number are floating point types.

Four. Data type conversions

We're going to convert the data built-in to the type, just use the data type as the function name.

The following 4 functions can be used when converting data types:

int (x) is converted to an integer

Float (x) converts x to a floating-point number

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

Complex (x, y) is converted to a complex number, the real part is x, and the imaginary part is Y. X and y are numeric expressions

Five. Constant

A constant is a variable that cannot be changed, such as a commonly used mathematical constant, π is a constant, and in Python, a constant is usually represented by a variable name in all capitals.

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

Pi: Mathematical constant pi (pi, usually expressed in π)

E: mathematical constant E, i.e. natural logarithm

Variable

In Python, variables are names that point to various types of values, the use of variables is very loose, there is no obvious variable declaration, and the type is not fixed

You can assign an integer to a variable, or you can assign a floating-point number to a variable, for example:

A=5

A is what we call a variable, and the data type of variable A is an integral type

Float (a)

The data type of variable A is converted to floating point, so it is very convenient to use variables in Python.

Function

Type (): Returns the data type in parentheses

Num=12

Print type (num)

Output <type ' int ' >

ID (): Return memory address

Operator

Assignment Operation: =

Arithmetic operations: +,-, *,/,%

Relational operations:>, <, >=, <=,! =, = =

Logical operation: And,or,not

Introduction to this end, thank you!

Self-hing Artificial Intelligence---Understanding the basic data types and operations of the Python language

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.