Python variables and data types in a detailed

Source: Internet
Author: User
This article mainly describes Python variables and data types in detail. Have a good reference value, follow the small series together to see it

Python variables and data types

    1. Data types in Python

    2. Python's print statement

    3. Comments for Python

    4. What is a variable in python

    5. Defining strings in Python

    6. Raw strings and multiline strings in Python

    7. Unicode strings in Python

    8. Integers and floating-point numbers in Python

    9. Boolean type in Python

Data types in Python

A computer is a machine that can do mathematical calculations as the name implies, so a computer program can handle a variety of values. However, the computer can handle far more than the numerical value, but also can deal with text, graphics, audio, video, web and other kinds of data, different data, need to define different data types. In Python, there are several types of data that can be processed directly:

One, integer

Python can handle integers of any size, including, of course, negative integers, and in a Python program, integers are represented in exactly the same way as mathematically, for example: 1,100,-8080,0, and so on.

Computer because of the use of binary, so, sometimes hexadecimal notation is more convenient, hexadecimal with 0x prefix and 0-9,AF, such as: 0XFF00,0XA5B4C3D2, and so on.

Second, floating point number

Floating-point numbers, which are decimals, are called floating-point numbers because, when represented by scientific notation, the decimal position of a floating-point number is variable, for example, 1.23x10 ^9 and 12.3x10 ^8 are equal. Floating-point numbers can be written in mathematical notation, such as 1.23,3.14,-9.01, and so on. But for very large or very small floating-point numbers, it must be expressed in scientific notation, the 10 is replaced with E, 1.23x10 ^9 is 1.23e9, or 12.3e8,0.000012 can be written 1.2e-5, and so on.

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.

Three, string

strings are arbitrary text enclosed in ' or ', such as ' abc ', ' XYZ ', and so on. Note that the ' or ' itself is only a representation, not a part of the string, so the string ' abc ' only a,b,c these 3 characters.

Four, Boolean value

The Boolean value is exactly the same as the Boolean algebra, with a Boolean value of only true, false two, or true, or false, in Python, which can be used to indicate a Boolean value directly with True, false (note case), or 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.

Five, null value

The 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.

Practice Code

1. Computes the sum of decimal integers 45678 and hexadecimal integers 0x12fd2. Print 45678 + 0x12fd22. Please use a string to represent the learn Python in IMOOC. Print "Learn Python in Imooc" 3. Please calculate the Boolean value of the following expression (note = = to determine equality): Print < print 0xFF = = 255 Result: False True


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.