Python: List the special variables used within the language

Python Basic: Exercise-97 with Solution

Write a Python program to list the special variables used in the language.

Sample Solution:

Python Code:

# Import the necessary modules.

# Create a set 's_var_names' containing unique variable names in the global namespace.
s_var_names = sorted((set(globals().keys()) | set(__builtins__.__dict__.keys())) - set('_ names i'.split()))

# Print an empty line for formatting.

# Join variable names in groups of 8 and print them for better readability.
print( '\n'.join(' '.join(s_var_names[i:i+8]) for i in range(0, len(s_var_names), 8)) )

# Print an empty line for formatting.

Sample Output:

ArithmeticError AssertionError AttributeError BaseException BlockingIOError BrokenPipeError BufferError BytesW
ChildProcessError ConnectionAbortedError ConnectionError ConnectionRefusedError ConnectionResetError Deprecati
onWarning EOFError Ellipsis                                                                                   
EnvironmentError Exception False FileExistsError FileNotFoundError FloatingPointError FutureWarning GeneratorE
IOError ImportError ImportWarning IndentationError IndexError InterruptedError IsADirectoryError KeyError     
KeyboardInterrupt LookupError MemoryError NameError None NotADirectoryError NotImplemented NotImplementedError
OSError OverflowError PendingDeprecationWarning PermissionError ProcessLookupError RecursionError ReferenceErr
or ResourceWarning 
 filter float format frozenset getattr globals hasattr hash                                                    
help hex id input int isinstance issubclass iter                                                              
len license list locals map max memoryview min                                                                
next object oct open ord pow print property                                                                   
quit range repr reversed round set setattr slice                                                              
sorted staticmethod str sum super tuple type vars                                                             


Flowchart: List the special variables used within the language.

Python Code Editor:


Previous: Write a Python program to print the current call stack.
Next: Write a Python program to get the system time.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

Follow us on Facebook and Twitter for latest update.