Python: Empty a variable without destroying it
Python Basic: Exercise-122 with Solution
Write a Python program to empty a variable without destroying it.
Sample data: n=20
d = {"x":200}
Expected Output: 0
{}
d = {"x":200}
Expected Output: 0
{}
Sample Solution:-
n = 20
d = {"x":200}
l = [1,3,5]
t= (5,7,8)
print(type(n)())
print(type(d)())
print(type(l)())
print(type(t)())
print(type(0))
print(type(0.0))
print(type(0j))
print(type("0"))
print(type((0,)))
print(type([0]))
print(type({0}))
print(type({0:0}))
========== RESTART: F:/Python_APSC/py-ex-basic-122.py ===========
0
{}
[]
()
<class 'int'>
<class 'float'>
<class 'complex'>
<class 'str'>
<class 'tuple'>
<class 'list'>
<class 'set'>
<class 'dict'>
>>>
沒有留言:
張貼留言