"TypeError"의 두 판 사이의 차이

(새 문서: category: Error ;TypeError ==Python== category: Python <source lang='Python'> a = 5 / '2' # TypeError: unsupported operand type(s) for /: 'int' and 'str' </source> <source la...)
 
잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(다른 사용자 한 명의 중간 판 3개는 보이지 않습니다)
4번째 줄: 4번째 줄:
==Python==
==Python==
[[category: Python]]
[[category: Python]]
<source lang='Python'>
<syntaxhighlight lang='Python'>
a = 5 / '2'
result = 5 / '2'
# TypeError: unsupported operand type(s) for /: 'int' and 'str'
# TypeError: unsupported operand type(s) for /: 'int' and 'str'
</source>
</syntaxhighlight>
<source lang='Python'>
<syntaxhighlight lang='Python'>
def divide(a, b):
def divide(a, b):
     try:
     try:
         c = a / b
         result = a / b
     except TypeError:
     except TypeError:
         return False
         return False
     return c
     return result


print( divide( 4, 2 ) )
print( divide( 4, 2 ) )
20번째 줄: 20번째 줄:
# 2.0
# 2.0
# False
# False
</source>
</syntaxhighlight>
<syntaxhighlight lang='Python'>
iter(1)
# TypeError: 'int' object is not iterable
</syntaxhighlight>


==같이 보기==
==같이 보기==
*[[ZeroDivisionError]]
*[[ZeroDivisionError]]
*[[자료형]]

2020년 11월 2일 (월) 02:31 기준 최신판

TypeError

1 Python[ | ]

result = 5 / '2'
# TypeError: unsupported operand type(s) for /: 'int' and 'str'
def divide(a, b):
    try:
        result = a / b
    except TypeError:
        return False
    return result

print( divide( 4, 2 ) )
print( divide( 4, '2' ) )
# 2.0
# False
iter(1)
# TypeError: 'int' object is not iterable

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}