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

沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

 2024_09 作業3  (以Node-Red 為主  Arduino 可能需要配合修改 ) Arduino 可能需要修改的部分 1)mqtt broker  2) 主題Topic (發行 接收) 3) WIFI ssid , password const char br...