만약 args
이 문자열이라면 args
이 정수이고 ather 일이라면 하나만 할 필요가 있습니다.변수 유형을 확인하는 방법은 무엇입니까? Python
어떻게 형을 구울 수 있습니까? 예 : 우리가 변수 인수의 타입이 정수 리터럴 0
같은 경우 비교하는 위에는 경우,
if type(args) is type(0):
blabla
:
def handle(self, *args, **options):
if not args:
do_something()
elif args is integer:
do_some_ather_thing:
elif args is string:
do_totally_different_thing()
당신의 권리입니다. 그것은 목록입니다. – Pol
'isinstance (s, types.IntType)'만을'isinstance (s, int)'보다 더 선호합니까? 아니면 두 종류의 문자열에 대해 언급 한 것과 일치합니까? 그냥 궁금해서. –
귀하의 솔루션은 python 3.1과 호환되지 않습니다! – banx