Python Intermediate

1. isinstance()

cc = list()
print(isinstance(cc, list))
#True
print(isinstance(cc, tuple))
#False

2. assert

assert conditions
if not conditions:
    raise AssertionError
def remainder(number, divisor):
    return number % divisor
assert remainder(20, 7) == 6
assert remainder(20, 7) == 2
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-11-81198d9fbb63> in <module>()
----> 1 assert remainder(20, 7) == 2

AssertionError: 

Reference


© 2018. All rights reserved.

Powered by Hydejack v7.5.0