After programming the program, use various means to conduct error checking and troubleshooting. The correctness of a program is not only reflected in the completion of normal functions, but more importantly, the correct handling of unexpected situations. From a psychological perspective, developers and debuggers should not be the same person. This article will share with you a detailed explanation of Python tuning knowledge, hoping to help you.
import pdb age = int(input("请输入你家狗狗的年龄: ")) print("")#加入断点pdb.set_trace()if age < 0: print("你是在逗我吧!")elif age == 1: print("相当于 14 岁的人。")elif age == 2: print("相当于 22 岁的人。")elif age > 2: human = 22 + (age - 2) * 5 print("对应人类年龄: ", human)
Add breakpoint
import pdb pdb.set_trace()
Start running debugging
##--> ; The arrow indicates the current statement;
(Pdb) indicates waiting for debugging instructions.
#hCommand (help)
You can view all debugging instructions.
lInstructions (list)
View the code context.
pCommand
is used to view variables. Usage:
p Variable name
For example, view the value of the age variable
Command (next) Single-step execution instructions.
Command (break) Add the specified breakpoint. Usage:
b line number
Run to the breakpoint
Enter the function After we modified the original code , add test function. This command can enter the function for debugging
The execution code returns from the current function
import pdb age = int(input("请输入你家狗狗的年龄: ")) print("")#加入断点pdb.set_trace()if age < 0: print("你是在逗我吧!")elif age == 1: print("相当于 14 岁的人。")elif age == 2: print("相当于 22 岁的人。")elif age > 2: human = 22 + (age - 2) * 5 print("对应人类年龄: ", human)
import pdb pdb.set_trace()
-->
(Pdb)
indicates waiting for debugging instructions.
You can view all debugging instructions.
View the code context.
is used to view variables. Usage: p Variable name
For example, view the value of the age variable
b line number
##c
s
Instruction (step)r
Instruction (return)
Execution code returns from the current function
Related recommendations:
PHP prints the calling function entry address (stack) to facilitate debugging
Node.js learning summary debugging Code method_node.js
PHP prints the calling function entry address (stack) to facilitate debugging
The above is the detailed content of Detailed explanation of Python debugging knowledge. For more information, please follow other related articles on the PHP Chinese website!