0. ago Introduction
I finally finished the postgraduate entrance examination. I started again with python. Think about the data structure of C++ and sophomore. You have to make up for the basic knowledge. Start with the basics, and then slowly transition numpy, opencv2, etc. , I used to use MATLAB before, but it is a bit fierce to ban MATLAB in the beautiful country. Let's switch to python. Not only is it small in size, but it is also well done with open source. Many packages are very interesting.
I only fill up the basic knowledge and some packages that may be used in the later stage. As for the turtle in the book, it is a bit fancy, just play it normally, and now I don’t waste time.
If you want to learn basic grammar, just tap it in Jupiter Lab.
1. Introduction to Python
When I think about the summer camp, I was asked by the teacher what is the advantage of Python. At that time, I was not only nervous, but also because I learned too little and talked nonsense. I hope I can have a better experience after this study.
Python was created by Guido van Rossum of New Zealand in 1990. It is named after the flying circus of the British popular comedy "Monty Python". van Rossum takes Py development as a hobby. Py is a popular programming language widely used in industry and academia because of its simple, concise and intuitive syntax and extended libraries.
Python is a widely used language . In fact, I think that each language is actually widely used. Each language should have its own unique advantages. Therefore, it is impossible for everyone to learn everything. You can learn what you use. If you really When you encounter a need, it is enough to read the documentation to solve your own problems. It is impossible for you to let me be an RSer to do a Web (but I do plan to build a blog Web by myself, hahahahahaha)
Python is a facet Object programming language, namely OOP (Object Oriented Programming). Python data are all objects created by classes. That is, a type or a certain kind of class, it can define objects of the same type, these objects have the same attributes and the same method of operating these objects, object-oriented programming is a powerful tool for the development of reuse software.
Python is an interpretive language, namely (Illustrative language) , which is translated and executed by an interpreter, one sentence at a time, which is why you can execute one sentence by typing a sentence in the terminal or console, while c++, c Run after it needs to be compiled.
2. Some basic grammar
Because I am a professional RS farming, not specializing in computers, so here starting from the most basic grammar, print
, eval
, 格式化
, 运算符号
and so on. Bring back the forgotten sophomores.
Interactive digital input should book a classic example of, Python inside through a = eval(input('请输入你要的数字'))
to complete the input needed to process an assignment, and then perform basic arithmetic symbols.
name | meaning |
---|---|
+ | addition |
- | Subtraction |
* | multiplication |
/ | Floating point division |
// | Division of integers |
** | index |
% | Surplus |
Like here before, exponential calculations are used less, but it seems to be used a lot when typing LaTeX. The key point is to pay attention to division, whether it is integer division or floating point division, and whether to find the remainder or the integer division.
Operator | meaning |
---|---|
+= | Assignment addition |
-= | Assignment subtraction |
*= | Assignment multiplication |
/= | Floating point assignment division |
//= | Integer assignment division |
%= | Assignment remainder |
**= | Assignment index |
I remember freshman rarely use these operators, may be their own code written in too little of it, mark it, for example a += 1
, is actually running two statements, the first a + 1
and then assign the result to a, the rest is true,
This is run in Jupyter Lab, which is the characteristic of interpreted languages~~ Like MALTAB, python, java, it has a very good environment for early learning. Just look at the effect-the important thing is to look at the enhanced operators.
3.Python built-in functions
function | description |
---|---|
abs (var) | Returns the absolute value of x |
max(var1,var2) | Return x 1, x 2 x_1,x_2x1,x2The maximum of |
min (var1, var2) | Return x 1, x 2 x_1,x_2x1,x2The minimum of |
pow (var1, var2) | Return var 1 var 2 var_1^{var_2}v a r1v a r2Value, similar to a**b |
round(var) | Returns the integer closest to x, if x and two integers are close to the same, return an even value |
round(x,n) | Floating point value with n decimal places after the decimal point |
It seems to be similar to MATLAB's syntax, that is, MATLAB's matrix expression is more 6, anyway, just write it down while reading.
fabs(var) | Treat var as a floating point number and return its absolute value |
---|---|
ceil (var) | var goes up to the nearest integer. Then return |
floor (var) | var takes the nearest integer down and returns |
exp (var) | Return the power function evare^{var}ethe value of v a r |
log (var) | Returns the natural logarithm of var |
log (var, base) | Returns the logarithm of var based on base |
sqrt (exists) | Returns the square root of var |
sin (var) | Returns the sine of var |
degree (var) | Convert var from radians to angles |
radians(var) | Convert var from angle to radians |
As for some cos、acos、tan
is a very conventional grammar, not playing.
And π \piπ sumeee is also defined in the math module, throughmath.pi
andmath.e
be poured into them, i.e.import math
allow you to use the predefined variables, which are in fact needmath
packets, for examplemath.sqrt(4)
, can not be simply usedsqrt(4)
.
4. With regard to print
some of the operations
print
some of the operations
4.1 Basic operation of ASCII code
This is mainly ASCII some basic operations, code escape character some basic operations.
#ord(var)返回 var 的 ASCII 码
ord('A')
#chr(var)返回 var ASCII 码对应的字符
chr(77)
First, about ASCII two basic operation code, the first ord(var)
return is 'A' letter corresponding to the ASCII code, chr(var)
returns the ASCII code corresponding to the letters.
Just take a look, it's quite basic
4.2 Basic operation of escape characters
Character escape sequence | name | Value |
---|---|---|
\b | Backspace | 8 |
\t | Tabs | 9 |
\n | Newline | 10 |
\f | Form feed | 12 |
\r | Carriage return | 13 |
\\ | Backslash | 92 |
\’ | apostrophe | 39 |
\" | Double quotes | 34 |
#通过转义字符打印带双引号的语句
print("\"我真的好累啊\"")
#打印有退格符的语句
print('\b 我真的好累啊')
#打印有制表符的语句
print('\t \"我真的好累啊\"')
# 打印有换行符的语句
print('\n \"我真的好累啊"')
Let’s take a look at the effect~-~, it’s actually very basic, but it’s better to really start from 0. In fact, many of the symbols I typed in the blog form have escaped characters inside. If you use more, it’s over!