2018年1月11日 星期四

Python: Empty a variable without destroying it

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
{}
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'>
>>> 

沒有留言:

張貼留言

MQTT Explorer 與 Node-Red 介面的實驗

 MQTT Explorer 與 Node-Red 介面的實驗 MQTT EXplorer 與 Node-Red介面的設定 (1) 設定  MQTT EXplorer Client    (2)        Node-Red LED ON  --> MQTT Explor...