在Python中,你可以使用`type()`函数和`isinstance()`函数来判断数据类型。以下是使用这些函数的示例:
使用`type()`函数
```python
x = 5
print(type(x)) 输出:
y = 3.14
print(type(y)) 输出:
z = "Hello"
print(type(z)) 输出:
lst = [1, 2, 3]
print(type(lst)) 输出:
tpl = (1, 2, 3)
print(type(tpl)) 输出:
dct = {'a': 1, 'b': 2}
print(type(dct)) 输出:
st = {1, 2, 3}
print(type(st)) 输出:
使用`isinstance()`函数
```python
x = 5
print(isinstance(x, int)) 输出: True
y = 3.14
print(isinstance(y, float)) 输出: True
z = "Hello"
print(isinstance(z, str)) 输出: True
lst = [1, 2, 3]
print(isinstance(lst, list)) 输出: True
tpl = (1, 2, 3)
print(isinstance(tpl, tuple)) 输出: True
dct = {'a': 1, 'b': 2}
print(isinstance(dct, dict)) 输出: True
st = {1, 2, 3}
print(isinstance(st, set)) 输出: True