i2tutorials

Globals() method in Python Built in Function

Globals() method in Python Built in Function

 

globals method in built in function returns the current global symbol table as dictionary.

A symbol table is nothing but a data structure which is maintained by a compiler which contains all the necessary information required by a program. The table contains variable names, methods, classes etc.

The symbol table is of 2 types

 

Syntax:

Globals()

 

Parameters

Globals so not have any parameters.

 

Example-1:

 

Without adding variable

x = globals()

 

Output:

Globals() method in Python Built in Function

 

Example-2:

 

By adding variable

age = 24
globals()['age'] = 30
print('The age is:', age)

 

Output:

Exit mobile version