w3resource

Python: List the special variables used within the language

Python Basic: Exercise-97 with Solution

List Special Variables

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.
print()

# 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.
print()

Sample Output:

ArithmeticError AssertionError AttributeError BaseException BlockingIOError BrokenPipeError BufferError BytesW
arning                                                                                                        
ChildProcessError ConnectionAbortedError ConnectionError ConnectionRefusedError ConnectionResetError Deprecati
onWarning EOFError Ellipsis                                                                                   
EnvironmentError Exception False FileExistsError FileNotFoundError FloatingPointError FutureWarning GeneratorE
xit                                                                                                           
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                                                             
zip   

Flowchart:

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.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/python-exercises/python-basic-exercise-97.php