First--python data basic types and operators

Source: Internet
Author: User

Data type

First, the basic data type:

shape (int), float (float), character (String), Boolean (bool), null (none);

    • Digital

123 is an example of an integer.
Long integers are just larger integers.
3.23 and 52.3E-4 are examples of floating-point numbers. The e tag represents a power of 10. Here, 52.3E-4 means 52.3 * 10-4.
( -5+4j) and (2.3-4.6j) are examples of complex numbers.
The complex number (complex) consists of the real and imaginary parts, the general form is X+yj, where x is the real part of the complex, and y is the imaginary portion of the complex, where x and y are real numbers.

    • Integral type:

On a 32-bit machine, the number of integers is 32 bits and the value range is -2**31~2**31-1, which is -2147483648~2147483647
On a 64-bit system, the number of integers is 64 bits and the value range is -2**63~2**63-1, which is -9223372036854775808~9223372036854775807

    • Floating point number:
Floating-point numbers are also decimals, such as 1.23,3.14,-9.01, for very large or very small floating-point numbers, the need to use scientific technique number method, the 10 with e alternative, 1.23 x10* is 1.23e*,0.000012 can be written 1.2e-5, etc. Integers and floating-point numbers are stored in different ways within the computer, and integer operations are always accurate, and floating-point operations may have rounding errors;
    • String:
The string is any text enclosed in "or", such as ' abc ', ' XYZ ' and so on, if ' itself is also a character, can be used "", such as "I m OK", including I, ', M,, O, K these 6 characters (space is a character) if the string contains both ' and contains ', you can use \   To indicate: ' I\ ' m \ ' ok\ '! ' The content is I ' M "OK"!\n means that the newline \ t means that the tab \ itself is to be escaped, using \ \ If there are many characters in the Python string that need to be escaped, you need to add a lot of strings, in order to simplify, Python is allowed to use R ' ' to indicate that the inner string is not escaped; &G t;>> print ' \\\t\\ ' >>> print R ' \\\t\\ ' if there is a lot of line breaks in the string, it's not good to read in a single line, and in order to simplify, Python allows the use of "" "" "" "" "" "" "format to represent multiple lines of content;string concatenation: Each time you create a string, you need to open a contiguous space in memory, and once you need to modify the string, you need to open up again, the evil of the + sign every time there will be a re-opening a space within
    • Boolean value:
The Boolean value is exactly the same as the Boolean algebra, with a Boolean value of only true, false two values (1 or 0), either True or false, in Python you can directly use True, False to denote Boolean values (note case), Boolean values can be used with and, or, Not operations, and operations are and operations, only all of the results of the True,and operation is the true;or operation is or operation, as long as one of the true,or operation results is the true;not operation is a non-operation, it is a single-mesh operator, the true to False, Turn false to true;
    • Null value:
The null value is a special value in Python, with none, none is not understood as 0, because 0 is meaningful, and none is a special null value; Python five standard data types:
    • Digital
    • String
    • List
    • Meta-group
    • Dictionary
Operator
Arithmetic operations: Comparison operations: Assignment operations:

Logical operation:

Member Operations:

Identity operation:

Bit operations:

#!/usr/bin/pythona= 60#= 0011 1100b = 13#= 0000 1101c =0 C= A & B;#0000 1100Print "Line 1-value of C is", c c= A | b#1101 = 0011Print "Line 2-value of C is", c c= a ^ b;#0001 = 0011Print "Line 3-value of C is", c c= ~a;#-61 = 1100 0011Print "Line 4-value of C is", c c= a << 2;#0000 = 1111Print "Line 5-value of C is", c c= a >> 2;#= 0000 1111Print "Line 6-value of C is"+ D
View Code

Operator Precedence:

First--python data basic types and operators

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.