Python data types and variables

Source: Internet
Author: User

Data type:

In Python, there are several types of data that can be processed directly:

① integer: Python can handle integers of any size, including, of course, negative integers, which are represented in the program in the same way as mathematically, such as 1,100,-8080,0 and so on.

Because the computer uses binary, it is sometimes convenient to use hexadecimal notation for integers, and hexadecimal is represented by 0x prefixes and 0-9,,a-f. For example: 0XFF00,0XA5B4C3D2, and so on.

② floating-point numbers: floating-point numbers, which are decimals, become floating-point numbers because, when represented by scientific notation, the decimal position of a floating-point number is variable.

Integers and floating-point numbers are stored inside the computer in different ways, and integer operations are always accurate (is division accurate?). Yes! ), and the floating-point operation may have rounding errors.

③ string: A string is any text enclosed in single or double quotation marks, such as ' abc ', ' XYZ ', and so on. Note that the "and" "itself is only a representation, not a part of the string, so the string ' abc ' only a,b,c these 3 characters. If ' itself is also a character, it can be enclosed in '.

What if the inside of a string contains both ' and ' contains '? You can use the escape character \ To identify, for example:

' i\ ' m \ "Ok\"! '

The string content represented is:

I ' m "OK"!

The escape character \ can escape many characters, such as \ n for newline, \ t for tabs, and the character \ itself to escape, so \ \ means the character is \, you can print the string in Python's interactive command line with print ().

If there are many characters in the string that need to be escaped, you need to add a lot of \, in order to simplify, Python also allows to use R ' ' to indicate that the string inside of ' is not escaped by default.

If there is a lot of line wrapping inside the string, it is not good to read it in a line, and in order to simplify, Python allows the "..." format to represent multiple lines of content.

④ Boolean value:

The Boolean value is exactly the same as that of the Boolean algebra, with a Boolean value of only true and false. Two values. In Python, you can directly use True, False to indicate a Boolean value (note case), or you can calculate it by Boolean operations:

Boolean values can be operated with and, or, and not.

The and operation is associated with an operation, and only the result of all true,and operations is true.

An OR operation is an operation, as long as one of the true,or operation results is true.

The not operation is a non-operation, which is a single-mesh operator that turns true to False,false to true.

Boolean values are often used in conditional judgments.

if age >=:    print('adult')Else :     Print ('teenager')

⑤ null: A null value is a special value in Python, denoted by none. None cannot be understood as 0, because 0 is meaningful, and none is a special null value. In addition, Python provides a variety of data types such as lists, dictionaries, and also allows you to create custom data types, which we'll continue to talk about later.

⑥ variables: The concept of variables, in computer programs, variables can be not only a number, but also any data type.

Variables are represented in the program by a variable name. The table name must be a combination of uppercase and lowercase English, numeric, and _, and cannot begin with a number.

In Python, equals = is an assignment statement that assigns any data type to a variable, and the same variable can be assigned repeatedly. And you can make different types of variables.

Python data types and variables

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.