Python is very convenient to process strings. It takes some time to make a summary:
------ Function -------------------- meaning --------------------
ABS (number) returns the absolute value of a number.
Cmath. SQRT (number) returns the square root, which can also be applied to negative numbers.
Float (object) converts string and number to floating point
Help () provides interactive help
Input (prompt) to get user input
INT (object) converts string and number to integer
Long (object) converts string and number to long integer
Math. Ceil (number) indicates the upper integer of the returned number. The type of the returned value is floating point.
Math. Floor (number) returns an integer in the lower house of the number. The type of the returned value is a floating point number.
Math. SQRT (number) returns the square root, not applicable to negative numbers
Pow (X, Y [, Z]) returns the Y Power of X (returns the result modulo Z)
Raw_input (prompt) gets user input. The returned type is string.
String Representation of the Repr (object) Return Value
Round (number [, ndigits]) rounds the number according to the given precision
STR (object) converts a value to a string
------------------------------------------------------
Input (): print the string and use the result as a new prompt.
Then Input 6
>>>x=input("please input x:")please input x:6>>>print(x)6
Raw_input (): all inputs are treated as raw data in the same string.
It is different from input ().
Linux (this is not the case for testing on Windows)
When we enter the name, the following error will occur, and if the input name is in the form of a string, it will be okay.
>>> Name = input ("What is your name? ")
What is your name? "Loulijun"
This is acceptable, but the following method does not work.
>>>name=input("what is your name?")what is your name?loulijunTraceback (most recent class last): File "<stdin>", line 1, in <module> File "<string>",line 1, in <module>NameError:name 'loulijun' is not defined
The reason is that input considers the user to input a valid expression, but it is not actually
This problem can be avoided by using raw_input ().
>>>name = raw_input("what is your name?")what is your name?loulijun>>> print(name)loulijun
Pow (): Calculate the multiplication party
Same effect **
>>> 2**38>>>pow(2, 3)8
How to use the extension module
You can import the module by importing math or from math import SQRT.
>>>import math>>>math.floor(32.9)32.0>>>from math import sqrt>>>sqrt(9)3.0
Cmath Module
Because the math module can only process floating-point numbers, errors such as virtual numbers are reported, such as SQRT (-2). An error is reported.
If you import cmath, you can use it. This is also an extension of math.
>>>import cmath>>>cmath.sqrt(-1)1j