1. Enter cmd in the program and query the cmd.exe command program.
2. Query the subline text 3
code editor
in the program, open it, and write code in this program.
3. Basically all operations can be performed in the subline text 3 program.
4. ctrl+shift+P to install or uninstall the software.
5. ctrl+B or ctrl+R to run the program (available in the menu bar).
6. The meaning and use of operator symbols in python:
print(2+6) # means 2 plus 6, the output value is 8
print(10-2) #represents 10 minus 2, the output value is 8
print(2*4) #represents 2 times 4, the output value is 8
print(16/2) # means 16 divided by 2, the output value is 8.0
print(16//3) # Indicates that 16 is divided by 3 and rounded up, and the output value is 5 Note: The division (/) in C and C++ is equivalent to the division (//) in python
print(16%3) # indicates that 16 is divided by 3 and the remainder, the output value is 1
print(2**3) #represents 2 to the third power, and the output value is 8
print(2^3) #represents 2 XOR 3, the output value is 1
7, int represents an integer
float for floating point
str represents a string
Input: print(type(A)) The type of A can be displayed. If A is 2, the output is an integer type; if A is 42.0, the output is a floating-point number; if A is 'a' (where a is any number of types), the output is a string. ps: Add quotation marks '' to become a string, then the output is a string.
8.
Variable name
: generally start with a lowercase letter, including letters, numbers and underscores.
ps: cannot start with a number, cannot contain illegal characters (such as: @) and python keywords (such as: class).
9. In python,
+ is used between strings, which means splicing, and * means repetition
. But, like '1'+'2',
For example: first='throat'
second='warbler'
print(first+second)
The output is: throatwarbler
print(first*3)
The output is: throatthroatthroat
10.
In python, // means to take an integer; == means to determine whether the left and right sides are equal
.
11. Debugging
There are three types of program errors: Syntax error, Running error, and Semantic error.
12. Introduce pi into python, set the radius to 5, find the volume of the circle?
enter:
r=5
important math #Import math module
v=4/3*
math.pi
*r**3
print(v)
Then the output value is: 523.5987755982989
13. ctrl+z return
14. Math includes database functions (not all examples):
ceil(x) take the top
floor(x) base
fabs(x) takes the absolute value
factorial (x) factorial
hypot(x,y) sqrt(x*x+y*y)
pow(x,y) x的y次方
sqrt(x) 开平方
log(x)
log10(x)
trunc(x) 截断取整数部分
isnan (x) 判断是否NaN(not a number)
degree (x) 弧度转角度
radians(x) 角度转弧度
e = 2.718281828459045
pi = 3.141592653589793
15、
def + 函数名 定义函数名称
(ps:1、与变量名命名规则差不多,字母、数字、下划线,但不能以数字和下划线开头,也不能用关键词来作为函数名;2、避免函数名与变量名重复。);
例如:
def cost(apple_num);
apple_cost=.....
注:a、函数名后面的括号是空的,表示该函数不需要参数;
b、函数定义的第一行叫头部,剩下的叫函数体。函数头部的末尾必须有个冒号,函数体必须是相对函数头部有缩进,距离行首相对于函数头要有4个空格的距离。函数体可以有任意长度的语句。
eg:
def cal_cost_print(book_num):
book_cost = 24.95 * 0.6 * book_num + 0.75 * (book_num - 1)
print(book_cost)
cal_cost_print(60)
输出结果:942.4499999999999