Python data type (i)

Source: Internet
Author: User

  1. The shaping of Python
    During the coding process, we often have to deal with some integer numbers, and at most sometimes we can ask for their absolute value, for example:
    A = 100
    b =-20

    Print (a)

    Print (b.__abs__ ())
    The problem of type conversion between string and integer variables is most likely to occur when we acquire variables, especially between integers and strings.

  2. Python floating-point type
    In the floating-point operation, there are two methods to control the number of decimal points, choose a suitable method of their own OK
    A.round () built-in method
    Using the round () built-in method to take the decimal point precision is commonly used.
    When round (float) contains only numbers, it retains 1 decimal places by default and is rounded,
    For example:
    >>>round (2.5)

    3.0
    >>>round (4.4)
    4.0
    When round (float,ndigits), which contains numbers and precision, float represents the number, ndigits need to retain the precision, usually also rounding the rules, But in the case of. 5, if the number of digits before the trade-off is even, this is discarded directly if the odd one goes up to 1. In summary, the last digit of the decimal point can only be an even number.

    >>>round (2.555,2)
    2.56
    >>>round (2.545,2)
    2.54
    B. Using formatting
    When using formatting to decimal point accuracy, the rules and round are the same, and the last digit of the decimal point is the choice of even

  3. The Boolean type of Python
    The Boolean type is two values, one is false, the other is true, usually at the time of assignment, is a return value of the final judgment, and then the value is manipulated.
    Bool=false;
    print bool;

    Bool=true;
    print bool;

  4. Python strings and Common methods
    Strings are the most commonly used, and we use "," "." "" to define a string, for example:
    >>>str1= "AAAAAAA"

    >>>str2= "BBBBBBB"
    >>>str3= "CCCCCC"
    PRINT{STR1,STR2,STR3}
    {AAAAAA,BBBBBB,CCCCCC}
    But in the final display, Python itself saved the string for us with "to save, so the most canonical method is to define the string when using '
    Define a string:
    A = ' AAA '
    Print (dir (a))

This article is from the "brave Heart Zhao Xiao Bai" blog, please make sure to keep this source http://3024783.blog.51cto.com/3014783/1974617

Python data type (i)

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.