2018年1月11日 星期四

Python: Check if variable is of integer or string

Python: Check if variable is of integer or string

Python Basic: Exercise-144 with Solution

Write a Python program to check if variable is of integer or string.
Sample Solution :-
N=input("plaese input a number or string : ")
print(isinstance(N,int) or isinstance(N,str))

print(isinstance(25,int) or isinstance(25,str))
print(isinstance([25],int) or isinstance([25],str))
print(isinstance("25",int) or isinstance("25",str))

========= RESTART: F:/Python_APSC/py-ex-basic-144.py ==============
plaese input a number or string : a23
True
True
False
True
>>> 


沒有留言:

張貼留言

2026 作業3 RFID+ Telegram 練習

 2026 作業3  RFID+ Telegram  練習 (Wokwi 與 Telegram 二者溝通訊息反映比較慢 ) 歡迎 Alex 使用 RFID 控制系統 /on : 開啟 LED /off : 關閉 LED /flash : 閃爍模式 /timer : 開啟 5 秒 ...