Simple_home_control_system/tests/enum_test.py
2024-05-02 19:25:24 +08:00

57 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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)