"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...)
 
5번째 줄: 5번째 줄:
[[category: Python]]
[[category: Python]]
<source lang='Python'>
<source 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>
</source>
11번째 줄: 11번째 줄:
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 ) )

2014년 8월 21일 (목) 16:40 판

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

2 같이 보기

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