integer = 1print(type(integer)) # Result: <class 'int'>, and if it's a string then class will be str and so on.
# Checking the typefloat_class = 1.3print(isinstance(float_class, float)) # True
from ctypes import *uint = c_uint(1) # Unsigned integerprint(uint) # Output: c_uint(1)
# To actually get the value, you have to call .valueprint(uint.value)
# Change valueuint.value = 2print(uint.value) # 2
variable = "hello_world"print(type(variable) is str) # Trueprint(isinstance(variable, str)) # True
让我们比较python3中的两个方法performances
python3 -m timeit -s "variable = 'hello_world'" "type(variable) is int"5000000 loops, best of 5: 54.5 nsec per loop
python3 -m timeit -s "variable = 'hello_world'" "isinstance(variable, str)"10000000 loops, best of 5: 39.2 nsec per loop