Today is learning python programming content on digital programming and the use of some of the related functions:
1, Number: scalar storage, random access, can not be changed (after the number change will generate a new object)
NOTE: immutable type of change is a pointer rather than the content itself
python support octal: 0 at the beginning
Hex: beginning 0x
Double precision floating point type: may be represented by a direct scientific notation or decimal. Usually have a floating point value and a decimal point may be used optional suffix e n e between the index and the (+) or (-) indicates a negative exponent
2, plural:
The real part of the complex num.real #
num.imag # imaginary part of a complex number
num.conjugate () # Returns the complex conjugate of the complex
Mixed mode operator:
coerce (a, b) method:
If there is a plural number of operation, it will be transformed into another complex
If either operand is a long integer, the other will be converted to long integer
If there is a floating point operand, the other will be converted to floating point
Modulo operation:
Float modulo:
Suppliers for less accuracy is worth taking the difference between the product of the largest integer: x- (math.floor (x / y) * y)
Exponentiation: Left ** Right:
Symbols do not look left and right to see the sign:
>>>-3**2
-9
>>>(-3)**2
9
>>>4.0**-1.0
0.25
Bitwise Operators:
~ Num # unary, for every logical inverse of the :-( num + 1)
num1<<num2
num1>>num2
num1&num2
num1 ^ num2
num1 | num2
3, the function value of the plant:
bool (obj) # returns a Boolean value object
int (obj, base = 10) # Returns a string or numeric character represented by an object (base-band parameter is optional)
long()
float()
complex()
4, performance function:
coerce()
divmod(a,b)
Integer: return (except the floor, take the remainder)
Float: Returns (math.floor (num1 / num2), take the remainder)
Complex: return (math.floor ((num1 / num2) .real), remainder)
5, taking the difference of entire functions:
int () # Direct truncated fractional part (return type)
floor () # give integer closest to but less than the original (return float)
round () # get the nearest integer number of original (return floating-point type)
6, numerical computation built-in functions:
abs (num) # returns the absolute value
coerce () # num1 and num2 convert to the same type
divmod ()
pow (num1.num2, mod = 1) # take if num1 num2 power provided mod parameter, the calculation result of the modulo operation performed mod
round()
The following are Examples:
a. take. Determine whether the year is a leap year
#_auther_="stuwu79" #date:2019/10/18 year = int(input("please input a year:")) if (year % 4 == 0 and year % 100 != 0) or (year%4 == 0 and year%100 ==0): print("yes") else: print("no")
b. the greatest common divisor and least common multiple
#_auther_="stuwu79" #date:2019/10/18 a = int(input('please enter 1st num:')) b = int(input('please enter 2nd num:')) s = a * b while a % b != 0: a, b = b, (a % b) else: print(b, 'is the maximum common divisor') print(s // b, 'is the least common multiple')