Python: Empty a variable without destroying it
Empty Variable Without Deletion
Write a Python program to empty a variable without destroying it.
type() returns the type of an object, which when called produces an 'empty' new value.
Sample data: n=20
d = {"x":200}
Expected Output: 0
{}
Sample Solution-1:
Python Code:
Sample Output:
0 {} [] ()
Sample Solution-2:
Python Code:
Sample Output:
Original objects: ['python', {'x': 12}, [10, 12, 'sfsd'], (4, 5), 200] Empty the said variables without destroying it: ['', {}, [], (), 0]
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program to clear a list, dictionary, tuple, and set while preserving their type.
- Write a Python function that takes any variable and resets its value to its default empty equivalent.
- Write a Python program to empty a variable and check its memory address before and after clearing.
- Write a Python program to empty a nested dictionary without deleting its keys.
Go to:
Previous: Write a Python program to determine if variable is defined or not.
Next: Write a Python program to determine the largest and smallest integers, longs, floats.
Python Code Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.