Isinstance.md

Python을 μ£Όμ–Έμ–΄λ‘œ μ •ν•˜κ³  κ°œλ°œν•˜λ©΄μ„œ λ‹€μ–‘ν•œ λΌμ΄λΈŒλŸ¬λ¦¬λ“€ μ†ŒμŠ€μ½”λ“œλ₯Ό κΉŒλ³΄λŠ”λ° κ·Έλ•Œλ§ˆλ‹€ μžμ£Όλ³΄μ΄λŠ” λ‚΄μž₯ν•¨μˆ˜μΈ isinstance()에 λŒ€ν•΄ μ•Œμ•„λ³΄μ•˜λ‹€.

  • isinstance()

    • Python의 Built-in Method

    • def ininstance(x, A_tuple) -> bool

    • parameter

      • νƒ€μž… 검사할 μΈμŠ€ν„΄μŠ€

      • νŠΉμ • 클래슀 / 데이터 νƒ€μž…

    • output

      • bool

    class Animal:
        pass
    
    animal_instance = Animal()
    
    print("animal_instance-Animal: ", isinstance(animal_instance, Animal))
    # >>> animal_instance-Animal:  True
    
    class Monkey(Animal):
        pass
    
    monkey_instance = Monkey()
    
    print("monkey_instance-Monkey: ", isinstance(monkey_instance, Monkey))
    print("monkey_instance-Animal: ", isinstance(monkey_instance, Animal))
    # >>> monkey_instance-Monkey:  True
    # >>> monkey_instance-Animal:  True
    • μœ„μ˜ κ²°κ³Όλ₯Ό 톡해 isinstance()λŠ” μƒμ†μ˜ κ΄€κ³„μ—μ„œλ„ μ μš©λœλ‹€λŠ” 것을 확인할 수 μžˆλ‹€.

Last updated