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.
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
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;
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)