57 lines
1.1 KiB
Python
57 lines
1.1 KiB
Python
#!/usr/bin/env python
|
||
# -*-coding:utf-8 -*-
|
||
|
||
"""
|
||
# File : enum.py
|
||
# Time :2024/5/2 上午 4:53
|
||
# Modify :sityliu
|
||
# Author :蓝陌
|
||
# version :python 3.8
|
||
# Description:
|
||
"""
|
||
from enum import Enum
|
||
|
||
|
||
class Color(Enum):
|
||
RED = 1
|
||
GREEN = 2
|
||
BLUE = 3
|
||
TEST1 = 'a487'
|
||
|
||
|
||
def print_color_name(color):
|
||
if color == Color.RED:
|
||
print("红色")
|
||
elif color == Color.GREEN:
|
||
print("绿色")
|
||
elif color == Color.BLUE:
|
||
print("蓝色")
|
||
else:
|
||
print("未知颜色")
|
||
|
||
|
||
# 使用枚举类型替代if判断
|
||
def print_color_name_with_enum(color):
|
||
if color == Color.RED:
|
||
print("红色")
|
||
elif color == Color.GREEN:
|
||
print("绿色")
|
||
elif color == Color.BLUE:
|
||
print("蓝色")
|
||
else:
|
||
print("未知颜色")
|
||
|
||
def get_voice_data(data):
|
||
print(data.TEST1)
|
||
if not data:
|
||
print('空')
|
||
# 开灯
|
||
elif data == data.TEST1:
|
||
print(11)
|
||
|
||
|
||
# 测试
|
||
print_color_name(Color.RED)
|
||
print_color_name_with_enum(Color.GREEN)
|
||
get_voice_data(Color.TEST1)
|