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

沒有留言:

張貼留言

113 學年度第 1 學期 RFID應用課程 Arduino程式

113 學年度第 1 學期 RFID應用課程 Arduino程式 https://www.mediafire.com/file/zr0h0p3iosq12jw/MFRC522+(2).7z/file 內含修改過後的 MFRC522 程式庫 (原程式有錯誤) //定義MFRC522...