Python is a powerful multiparadigm computer programming language, optimized for programmer productivity, code readability, and software quality.

Python is a popular open source programming language used for both standalone pro- grams and scripting applications in a wide variety of domains. It is free, portable, pow- erful, and is both relatively easy and remarkably fun to use.

Debugging Python Code

  • Do nothing. When you make a mistake in a Python program, you get a very useful and readable error message (you’ll get to see some soon, if you haven’t already). This is often enough, read the error message, and go fix the tagged line and file. For many, this is debugging in Python.
  • Insert print statements. Probably the main way that Python programmers debug their code is to insert print statements and run again. Because Python runs immediately after changes, this is usually the quickest way to get more information than error messages provide. The print statements don’t have to be sophisticated—a simple “I am here” or display of variable values is usually enough to provide the context you need.
  • Use IDE GUI debuggers. For larger systems you didn’t write, and for beginners who want to trace code in more detail, most Python development GUIs have some sort of point-and-click debugging support.
  • Use the pdb command-line debugger. For ultimate control, Python comes with a source code debugger named pdb, available as a module in Python’s standard library. In pdb, you type commands to step line by line, display variables, set and clear breakpoints, continue to a breakpoint or error, and so on. You can launch pdb interactively by importing it, or as a top-level script. Either way, because you can type commands to control the session, it provides a powerful debugging tool.
  • Use Python’s –i command-line argument. Short of adding prints or running under pdb, you can still see what went wrong on errors. If you run your script from a command line and pass a -i argument between python and the name of your script(e.g., python –i m.py),Python will enter into its interactive interpreter mode (the >>> prompt) when your script exits, whether it ends successfully or runs into an error. At this point, you can print the final values of variables to get more details about what happened in your code because they are in the top-level namespace.

The Python Conceptual Hierarchy

From a more concrete perspective, Python programs can be decomposed into modules, statements, expressions, and objects, as follows:

  1. Programs are composed of modules.
  2. Modules contain statements.
  3. Statements contain expressions.
  4. Expressions create and process objects.

_Graph. Python Conceptual Structure Learning Python - 图1

Core Data objects

Table. Built-in objects

Object type Example literals/creation
Numbers 1234, 3.1415, 3+4j, 0b111, Decimal(), Fraction()
Strings ‘spam’, “Bob’s”, b’a\x01c’, u’sp\xc4m’
Lists [1, [2, ‘three’], 4.5],list(range(10))
Dictionaries {‘food’: ‘spam’, ‘taste’: ‘yum’},dict(hours=10)
Tuples (1, ‘spam’, 4, ‘U’),tuple(‘spam’),namedtuple
Sets set(‘abc’),{‘a’, ‘b’, ‘c’}
Files open(‘eggs.txt’),open(r’C:\ham.bin’, ‘wb’)
Booleans True, False
None None
Program unit types Functions, modules, classes
Implementation-related Compiled code, stack tracebacks

Figure. Python’s major built-in object types

image.png

image.png

image.png

Certificate :)

image.png