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

沒有留言:

張貼留言

Messaging API作為替代方案

  LINE超好用功能要沒了!LINE Notify明年3月底終止服務,有什麼替代方案? LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。 //CHANNEL_ACCESS_TOKEN = 'Messaging ...