How do I see all of Python's built-in variables and built-in functions?

Source: Internet
Author: User

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
    • Python
Method/Step
  1. 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. 2

    Input dir (__builtins__)

    Press ENTER.

  3. 3

    You can also:

    Import Builtins

    Dir (builtins)

    Press ENTER.

    The results obtained are the same as Dir (__builtins__).

  4. 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. 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. 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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.