- Datatype & Calculation
Using Pow Function(pow(x, y)) to calculate the x^y, and the values are able to be infinite.
There are four forms of integer system:
Decimal(very normal), Binary(start at 0b or 0B), Octal(starts at 0o or 0O), Hexadecimal(start at 0x or 0X).
Using round(x, d) to discard the decimals behind the dth decimal of the “x”. Floating numbers can be represented by the scientific notation. The symbol of “e” or “E” as a power based on 10, the form is:
4.3
e
−
3
4.3e-3
4.3e−3 or
9.6
E
5
9.6E5
9.6E5 which means
4.3
∗
1
0
−
3
4.3*10^-3
4.3∗10−3 and
9.6
∗
1
0
5
9.6*10^5
9.6∗105
Default d is zero.
Using “//” to get integer result of division. In Python Language the result of the division of two integers return floating number, it’s different from C++.
x
∗
∗
y
x**y
x∗∗y means Power Calculation(x^y), when y in value is fraction, it means Extraction of Root Calculation(the result of
10
∗
∗
0.5
10**0.5
10∗∗0.5 means sqrt(10)).
divmod(x, y): result and remainder of division, means (x//y, x%y), output the quotient and remainder simultaneously.
pow(x, y [, z]): Python gives the third parameter z, means(x**y)%z, and parameter z can be omitted.
max/min(x1, … , xn): means find the max/min value in the list of parameters, the count of parameters is able to be infinite.
There are three functions to change the type of data compulsively: int(x), float(x), complex(x), this functions can also identify the string value, for example, the result of “int(“123”)” is 123.
- Stringtype & Operation
There are two classes of String and four representation of them: a couple of “” or ‘’ only to represent single-line string, and a couple of “”" or ‘’’ can represent multiline string.
Python Language does not provide the representation of multiline comments, a couple of “”" means a string exactly, but if this string doesn’t assign a value to a parameter or have no more operation, it can be regarded as an annotation.
Why does Python Language have two types to represent the string: if you want to include double OR single ’ in the string, using a couple of " to define a single-line of string, for example:
“Das ist ein Faden(’)” or ‘Das ist ein Faden(")’. and if you want to include both ’ and " in a single-line string, using the “”" or ‘’’ to handle it.
There are two type to list the elements of string: forward increasing serial numbers and reverse decreasing serial numbers.
Slices the string:
Using [M : N] to slice the string, M absent means up to the begining, N absent means down to the end.
Using [M : N : K] to slice the string according to the step parameter K, e.g: “1234567890”[1 : 8 : 2], the result is “1357”.
If you want to print a string in a invert sequence, using [::-1] to handle it, e.g: “1234567890”[::-1], the result is “0987654321”.
Special characters in string: Escape
The use of \ is to represent the original mean of particular character. e.g: “Es gibt eine quote(”)", the result is: “Es gibt eine quote(”)".
There are some combinations of Escape Character to express some unprintable implication:
\b means Backspace, \n means move the cursor to the next line, \r means move the cursor to the start of this line.The operation of string:
+
+
+ means connect two strings.
∗
*
∗ (n * x or x * n)means copy the string n times.
in (a Key Word, x in s)means if x is the sub-string of s, return True, otherwise return False.
Using len(x) to return the length of string. WARNING: in Python Language, a Chinese character, a number, a English character all have the same length 1, if you input: len(“一二三456”), the result is: 6.
Using str(x) to make each type of x convert into string type.
hex(x) or oct(x): output the string of hexadecimal or octal lowercase of integer x.
str.lower() or str.upper(): make the string lower/upper.
str.split(sep = None): return a list which is constituded by the divided parts according to the parameter sep.
str.replace(old, new): return the copy of string, all of “old” are replaced by “new”.
str.center(width[, fillchar]): put the string str on the center according to the parameter width, “fillchar” is alternated.
str.strip(chars): delete the characters on the right/left of the string which is defined in the list “chars”.
str.join(iter): using parameter iter to separate the string, behind each character of the string, there is a iter. e.g: the result of join(“12345”) is “1, 2, 3, 4, 5”
min(s)/max(s): return the min/max element of s, WARNING: the elements in s should be comparable.
s.index(x)/s.index(x, i, j): return the position that x first appear from i to j in s.
- The overview of Time Library
Three types of function in Time Library:
Get the system time: time(), ctime(), gmtime().
Formatting the time: strftime(), strptime().
Timing programs: sleep(), perf_counter().
Using time() to get current Timestamp, the internal time value in computer, return a float type number.
Using ctime() to get current system time(date & time) in a easy-reading way, return a string just like “Fri Jan 26 12:11:16 2018”.
Using gmtime() to get current system date in a way which computers can deal with.
Using localtime() to get current system time in a way which computers can deal with.
time.strftime(tpl, ts): the parameter tpl is formatting template string used to define the effect of output. the parameter ts is internal Timetype varible in computer.
time.strptime(str, tpl): the parameter str is the time value in String format, tpl is formatting template string used to define the effect of input.
time.sleep(s): the program will stay for s second at screen.
Dynamic fresh in single line.
The essence of refresh is using post-printed characters to cover the pre-printed characters.
Change into next is not be allowed, print() should be controlled.
Able to go back: cursor should back to the pre-condition when finished print.
Different design functions for text progress bars:
NAME | TENDENCY | FUNCTIONS |
---|---|---|
Linear | Constant | f(x) = x |
EarlyPause | Speeds up | f(x) = x + (1-sin(2PIx + PI/2)/-8) |
LatePause | Slows down | f(x) = x + (1-sin(2PIx + PI/2)/8) |
SlowWavy | Constant | f(x) = x + sin(5PIx)/20 |
FastWavy | Constant | f(x) = x + sin(20PIx)/80 |
Power | Speeds up | f(x) = (x + 0.03*(1-x))^2 |
InversePower | Slows down | f(x) = 1-(1-x)^1.5 |
FastPower | Speeds up | f(x) = (x +(1-x)/2)^8 |
InverseFastPower | Slows down | f(x) = 1-(1-x)^3 |