Https://jingyan.baidu.com/article/7082dc1c071649e40a89bdb8.html
The Python interpreter has built in constants and functions called built-in constants (built-in Constants) and built-in functions (built-in Functions), how do we get all the built-in constants and function names in Python IDLE?
Tools/Materials
Method/Step
- 1
, open Python IDLE, I use Python 3.7, the interface is personalized. Your version differs, the interface is different, but the operation method should be the same.
- 2
Input dir (__builtins__)
Press ENTER.
- 3
You can also:
Import Builtins
Dir (builtins)
Press ENTER.
The results obtained are the same as Dir (__builtins__).
- 4
So what's the whole thing that's going to return?
As you can see, the returned result is ending with [start with], and the description is a list, and let's see how many elements there are in the table.
Input:
Len (dir (__builtins__))
Get a number, 154, that shows that the current version of Python has built-in constants and the total number of functions is 154.
- 5
Let's re-export the list and print it out one at a to see it better.
For item in DIR (__builtins__):
Print (item)
Press the ENTER key two times. In the default alphabetical order, first the capital letter A-Z, then the underscore (_), and then the lowercase letter A-Z, why is this order? This is true because the number of lowercase letters is larger than the number represented by the ASCII Code table, and the number that represents the underscore (_) is centered.
- 6
Print () is the default function for Python 3. Let's try:
Print (' Hello world ')
Builtins.print (' Hello World ')
__builtins__.print (' Hello World ')
The result is as follows, as you can see, the result is the same.
END
Precautions
- Dir () itself is a Python built-in function that allows us to see all the methods and properties of an object, and is useful for mastering the whole picture.
How do I see all the built-in variables and built-in functions for Python?