Number and sequence of Python core programming learning diaries

Source: Internet
Author: User
Tags floor division integer division uppercase letter

Chapter 5 figures

1. digit type

A. Python supports the following numeric types: integer, long, and Boolean. Double-precision floating point, decimal floating point, and plural

B. We recommend that you use the uppercase letter "L" to represent a long integer. In addition, integer and long integer are becoming unified. If necessary, the integer type will be converted to a long integer type, avoiding the trouble of crossing the value range.

C. double-precision floating point number (similar to double in C)

D, plural: both the real and virtual parts are floating point numbers. We recommend that you use the suffix "J" andProgramThe output is consistent. Num. Real, num. imag, num. Conjugate () indicate the real part of the plural, virtual part, and compound number.

2. Operators

A. Almost all operators supported by Python perform automatic data type conversion.

B. At present, Python still adopts the integer division operator rounded up method and will support real vendors in the future. The Division can be called through from _ future _ import division. The floor Division will be supported by the new operator.

C. The non-plural remainder is equivalent to X-(math. Floor (x/y) * Y ). Returns the remainder of a number: X-(math. Floor (x/y). Real) * Y)

D. The power operator has a higher priority than the one-dimensional operator of the left-side operand, and is lower than the one-dimensional operator of the right-side operand.

3. Built-in and factory Functions

A, INT (), long (), float (), complex (), bool () (all changed from built-in functions to factory functions)

B. built-in functions: ABS (), coerce (), divmod (), POW (), and round ().

C, only applicable to integers: hexadecimal conversion functions OCT (), Hex (); ASCII conversion functions CHR (), ord (); unichr ()

4. Related modules

A, decimal, array, math/cmath, operator, random

B. Random contains multiple pseudo-random number generators. Randrange (), uniform (), randint (), random (), choice ()

 

Chapter 6 sequence: String, list, and table column

1. Sequence type operators (applicable to all sequence types)

A, in, not in: OBJ [not] in sequence (return true or false)

B, seq [ind] (obtain the element whose subscript is IND); seq [ind1: ind2] (obtain the element set between ind1 and ind2 ); SEQ * expr (repeated expr times); seq1 + seq2 (connected sequence seq1 and seq2, used for low merging sequence efficiency );

C. Extend the slice operation. The third index value is used as the step size parameter. Sequence [: None] separates the entire sequence.

2. built-in functions

A, type conversion: List (ITER); STR (OBJ); Unicode (OBJ); basestring () (Abstract Factory function, cannot be instantiated or called); tuple (ITER)

B. Operation Type Functions: Len (), reversed (), sum () (the three functions only accept the sequence type), enumerate (ITER), sort (), zip () (accepts iteratable objects), max (), min () (accepts parameter tables in addition to ITER)

3. String

A. Do not import or use the string template for performance considerations. Use the % format operator or put the string in a list and then use the join () method.

B. the python syntax allows you to write several strings in the source code.

C. If you connect a common string to a unicode string, Python converts the common string to a unicode string before the connection operation.

D. The format operator is only applicable to strings: Very similarC LanguagePrintf () FormatCodeFormat_string % (arguments_to_convert)

E, string template: from string import template; original string operator (R/R), which is similar to the @ "" usage in C.

F, Unicode string operator (U/U): converts a string to a fully Unicode String object. (Original Unicode string: the Unicode operator must appear before the original string operator)

4. String built-in functions

The A, max (), and min () functions return the Maximum/minimum elements in the iterator or parameter column (strings are arranged according to ASCII code values)

B, enumerate (ITER): the object generates a tuple consisting of the index value and item value of each element of ITER. Zip () returns a list

5. unique features of strings:

A. a backslash with a single character represents a special character. You can also use the ASCII code value of \ 000 or \ XXX (octal or hexadecimal. Nul has no Terminator in Python

B. Three quotation marks allow a string to span multiple lines. A string can contain line breaks, tabs, and other special characters (mostly embedded code, such as HTML or SQL)

C. Unicode processing rules: When a string appears in a program, you must add a prefix U. Do not use the STR () function instead of Unicode (). Do not use an outdated string module, basically, it can only process ASCII characters normally. If it is not necessary, do not encode Unicode characters in the program. You can call the encode () function only when writing files, databases, or networks, correspondingly, the decode () function is called only when you need to read the data back.

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.