20171020_python Study Day Fifth

Source: Internet
Author: User

Today's mission (October 20)

Master Knowledge Points:
1. Learn Python's integral type
2. Learn Python's floating-point type
3. Learn the Boolean type of Python
4. Learn the Python string and common methods
corresponding to the ape lesson Chapter 4.1-4.4

Python has five standard data types:

    • Numbers (digital)
    • String (String)
    • List (lists)
    • Tuple (tuple)
    • Dictionary (dictionary)

1. Integral type (INT)

Int, Integer, RANGE 2 * * 31 to 2 * * 31-1, beyond this range is long integer, there are 2 binary, 8, 10, 16 When you represent integers in 8 notation, prefix with ' 0 ' in front and 16 prefix ' 0x '

>>> 017       #8进制15 >>> 0xF       #16进制15

Long integer type

A Long, integer, out of range of 2 * * 31 to 2 * * 31-1 digits. The suffix is ' L '. Other same as "integral type"

2. Float type (float)

Float, decimal, number of digits can be changed, such as: 12.1/(10 * * 8) and 1.21/(10 * * 7) are equal. For very small or very large numbers can be used in scientific notation, such as: 1.21e-09. The division of integers is accurate, and the division of floating-point types may be rounded.

A.round () built-in method

Using the round () built-in method to take the decimal point precision is most commonly used.

When round (float) contains only numbers, it retains 1 decimal places by default and takes rounding. Examples are as follows:

B. Using formatting

When using formatting to go to decimal precision, the rules and round are the same, and the last digit of the decimal point is a choice of even numbers, as in the following example:

Round (float, precision)

Rounding is performed first, if the last digit of the decimal precision is an even number, qualifying, if the last bit of the decimal precision is rounded up, then all digits after the original decimal point precision are discarded and guaranteed (the last digit of the decimal point must be even).

3. Strings (String)

String, enclosed in single or double or triple quotation marks. Quotation marks do not make strings, they represent only one symbol. such as: ' abc ', ' Hello World ', ' I ' m moumifan '. If the string contains ' or ', it is escaped with ' \ ' and the ' \ ' in the string itself is also escaped.

\ r: Enter, \ t: tab, \ n: Line break

Strings enclosed in three quotes can span multiple lines.

>>> string = "string" >>> print stringstring>>> string = ' string ' >>> print stringstring>>> string = ' i\ ' m string ' >>> print Stringi ' m string>>> print ' This is \ n, haha ' th  is is, haha>>> ' Thisishelloworld ' ' This\nis\nhello\nworld ' >>> print ' Thisishelloworld ' ' Thisishelloworld

Common methods of strings:

The string default is subscript, which starts with 0 by default.

Find, finds the string. If a return string is found to match the subscript information, if it does not match, return-1

Replace

Split

# #shell里面的awk的-F option

Join

Format

Strip

Comment for string

C. Boolean type

Boolean values are exactly the same as Boolean algebra, with a Boolean value of only two values, either, or, True False True False in Python, you can directly use True , represent a False boolean value (note case), or you can calculate it by Boolean:

>>> TrueTrue>>> FalseFalse>>> 3 > 2True>>> 3 > 5False

Boolean values can be used and , or and not operations.

andOperations are and operations, and only all are True , the result of the and operation is True :

>>> True and TrueTrue>>> True and FalseFalse>>> False and FalseFalse

orAn operation is or an operation, as long as one of them is True , the result of the or operation is True :

>>> True or TrueTrue>>> True or FalseTrue>>> False or FalseFalse

notAn operation is a non-operation, which is a single-mesh operator that turns True into False False True :

>>> not TrueFalse>>> not FalseTrue

Boolean values are often used in conditional judgments, such as:

if age >= 18:    print ‘adult‘else: print ‘teenager‘

D. String

20171020_python Study Day Fifth

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.