Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


What is ast.arguments in Python?

Adnan Abbas

Python ast module

The ast module (Abstract Syntax Tree)tree representation of source code allows us to interact with and modify the Python code.

Python comes with abstract syntax grammar that is subject to change with every Python release.

This module helps applications process syntax trees and find out what the current syntax grammar looks like programmatically.

Abstract syntax trees are great tools for program analysis and program transformation systems.

Example of an abstract syntax tree

ast.arguments method

ast.arguments( posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg, defaults ) is a class defined in the ast module that expresses the arguments of a function in Python. It expresses the arguments in the form of an Abstract Syntax Tree.

When the parse() method of ast is called on a Python source code that contains a function with some arguments, it invokes the ast.arguments class. This expresses the function’s arguments to a node in an ast tree data structure. The ast.arguments class represents the arguments node type in the ast tree.


  • posonlyargs, args and kwonlyargs are lists of arg nodes.

    arg is a class that represents a single argument in a list.

  • vararg and kwarg are single arg nodes that point to the *args, **kwargs parameters.

  • kw_defaults contains the list of default values for keyword arguments. If one is None, the corresponding argument is required.

  • defaults contains the list of default values for arguments passed positionally. If there are fewer defaults than required, they are interpreted as the last n arguments.



View all Courses

Keep Exploring