7_20 day24 13min 静态方法

本文介绍了一个简单的Python类定义示例,包括初始化方法和一个静态方法,并展示了如何调用这些方法。通过具体代码解释了类的属性设置及静态方法的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

class Room:
tag=1
def __init__(self,name,owner,width,length,heigh):
self.name=name
self.owner=owner
self.width=width
self.length=length
self.heigh=heigh


@staticmethod#类工具包,不和类也不和实例绑定,不能调用类,实例变量
def wash_body(a, b, c):
print('%s %s %s正在洗澡' % (a, b, c))

def test(x, y):
print(x, y)

Room.wash_body('alex','yuanhao','wupeiqi')
r1=Room('厕所','alex',100,100,100000)

print(Room.__dict__)
print(r1.__dict__)

转载于:https://www.cnblogs.com/yikedashuyikexiaocao/p/9339508.html

#include <stdio.h> #include <time.h> #include <string.h> #include "aip_common.h" #define ZERO (0) #define DEFAULT_YEAR (1900) #define DEFAULT_MON (1) #define HALFDAY (12) U4 main() { time_t u4_t_time_now = time(NULL); struct tm st_t_time_members; localtime_s(&st_t_time_members, &u4_t_time_now); // 中文星期数组 const U1* u1p_tp_cnweeks_members[] = { "日", "一", "二", "三", "四", "五", "六" }; // 英文月份数组 const U1* u1p_tp_enmonths_members[] = { "January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December" }; // 英文星期数组 const U1* u1p_tp_enweeks_members[] = { "Sunday", "Monday", "Tuesday", "Wednesday","Thursday", "Friday", "Saturday" }; // 日文星期数组 const U1* u1p_tp_jpweeks_members[] = { "日", "月", "火", "水", "木", "金", "土" }; // 格式1:2017年9月28日 星期四 14点26分13秒 printf("格式1:%d年%d月%d日 星期%s %d点%d分%d秒\n",st_t_time_members.tm_year + (U4)DEFAULT_YEAR, st_t_time_members.tm_mon + (U4)DEFAULT_MON, st_t_time_members.tm_mday,u1p_tp_cnweeks_members[st_t_time_members.tm_wday], st_t_time_members.tm_hour, st_t_time_members.tm_min, st_t_time_members.tm_sec); // 格式2:2017/9/28 星期四 14:26:13 printf("格式2:%d/%d/%d 星期%s %d:%02d:%02d\n",st_t_time_members.tm_year + (U4)DEFAULT_YEAR, st_t_time_members.tm_mon + (U4)DEFAULT_MON, st_t_time_members.tm_mday,u1p_tp_cnweeks_members[st_t_time_members.tm_wday], st_t_time_members.tm_hour, st_t_time_members.tm_min, st_t_time_members.tm_sec); // 格式3:2017/9/28 星期四 2:26:13(PM) U4 u4_t_time_halfday = st_t_time_members.tm_hour % (U4)HALFDAY; if ( (U4)ZERO == u4_t_time_halfday) { u4_t_time_halfday = (U4)HALFDAY; } else { } const U1* ampm_str; if ((U4)HALFDAY <= st_t_time_members.tm_hour) { ampm_str = "PM"; } else { ampm_str = "AM"; } printf("格式3:%d/%d/%d 星期%s %d:%02d:%02d(%s)\n",st_t_time_members.tm_year + (U4)DEFAULT_YEAR, st_t_time_members.tm_mon + (U4)DEFAULT_MON, st_t_time_members.tm_mday,u1p_tp_cnweeks_members[st_t_time_members.tm_wday], u4_t_time_halfday, st_t_time_members.tm_min, st_t_time_members.tm_sec,ampm_str); // 格式4:Thursday, September 28, 2017 14:26:13 printf("格式4:%s, %s %d, %d %02d:%02d:%02d\n",u1p_tp_enweeks_members[st_t_time_members.tm_wday],u1p_tp_enmonths_members[st_t_time_members.tm_mon], st_t_time_members.tm_mday, st_t_time_members.tm_year + (U4)DEFAULT_YEAR,st_t_time_members.tm_hour, st_t_time_members.tm_min, st_t_time_members.tm_sec); // 格式5:2017年9月28日(木) 2:26:13(PM) if ((U4)HALFDAY <= st_t_time_members.tm_hour) { ampm_str = "PM"; } else { ampm_str = "AM"; } printf("格式5:%d年%d月%d日(%s) %d:%02d:%02d(%s)\n",st_t_time_members.tm_year + (U4)DEFAULT_YEAR, st_t_time_members.tm_mon + (U4)DEFAULT_MON, st_t_time_members.tm_mday, u1p_tp_jpweeks_members[st_t_time_members.tm_wday], u4_t_time_halfday, st_t_time_members.tm_min, st_t_time_members.tm_sec,ampm_str); return ZERO; } 给数组加上初始化函数
08-06
#include <stdio.h> #include <windows.h> #include "time_display.h" #define MAX_TIME_STR (256) /* Maximum length of time string */ #define MAX_WEEK (7) /* Number of days in a week */ #define MAX_MONTH (12) /* Number of months in a year */ #define TIME_HALFDAY (12) /* Half-day point for AM/PM conversion */ #define TEST_ZERO (0) /* Zero value constant */ #define FORMAT_ERROR (0) /* Error code for format failure */ #define TEST_ONE (1) /* Numeric constant one */ #define TEST_FIVE (5) /* Numeric constant five */ #define CONDITIONONE (1) /* Format index constant 1 */ #define CONDITIONTWO (2) /* Format index constant 2 */ #define CONDITIONTHREE (3) /* Format index constant 3 */ #define CONDITIONFOUR (4) /* Format index constant 4 */ #define CONDITIONFIVE (5) /* Format index constant 5 */ /* Chinese weekday names */ static const U1* u1p_sp_TIME_WEEKZH[] = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" }; /* English weekday names */ static const U1* u1p_sp_TIME_WEEKEN[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; /* Japanese weekday abbreviations */ static const U1* u1p_sp_TIME_WEEKJP[] = { "日", "月", "火", "水", "木", "金", "土" }; /* English month names */ static const U1* u1p_sp_TIME_MONTHEN[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; /* Format time according to specified index */ static U4 u4_s_time_Format(U1 u1_a_format_index, SYSTEMTIME* stp_a_time_t, U1* u1p_a_time_bufferone, size_t u4_a_buf_size) { U4 u4_t_format_ret; /* Return value storage */ U2 u2_t_time_y; /* Year component */ S1 s1_t_time_m; /* Month component */ S1 s1_t_time_d; /* Day component */ S1 s1_t_time_h24; /* Hour in 24-hour format */ S1 s1_t_time_min; /* Minute component */ S1 s1_t_time_sec; /* Second component */ S1 s1_t_time_w; /* Weekday index */ S1 s1_t_time_h12; /* Hour in 12-hour format */ const S1* s1p_t_TIME_AMPM; /* AM/PM indicator */ /* Validate input parameters */ if (!u1p_a_time_bufferone || u4_a_buf_size < (U4)MAX_TIME_STR || !stp_a_time_t) { u4_t_format_ret = (U4)FORMAT_ERROR; /* Return error on invalid input */ } else { /* Extract time components from SYSTEMTIME structure */ u2_t_time_y = (U2)stp_a_time_t->wYear; s1_t_time_m = (S1)stp_a_time_t->wMonth; s1_t_time_d = (S1)stp_a_time_t->wDay; s1_t_time_h24 = (S1)stp_a_time_t->wHour; s1_t_time_min = (S1)stp_a_time_t->wMinute; s1_t_time_sec = (S1)stp_a_time_t->wSecond; s1_t_time_w = (S1)stp_a_time_t->wDayOfWeek; /* Convert 24-hour to 12-hour format */ if ((U1)TEST_ZERO == s1_t_time_h24 % (U1)TIME_HALFDAY) { s1_t_time_h12 = (U1)TIME_HALFDAY; } else { s1_t_time_h12 = s1_t_time_h24 % (U1)TIME_HALFDAY; } /* Determine AM/PM indicator */ if (s1_t_time_h24 >= (U1)TIME_HALFDAY) { s1p_t_TIME_AMPM = "PM"; } else { s1p_t_TIME_AMPM = "AM"; } /* Select format based on index */ switch (u1_a_format_index) { case (U4)CONDITIONONE: /* Chinese format with weekday */ u4_t_format_ret = snprintf(u1p_a_time_bufferone, u4_a_buf_size, "格式1:%u年%u月%u日 %s %u点%u分%u秒", u2_t_time_y, s1_t_time_m, s1_t_time_d, u1p_sp_TIME_WEEKZH[s1_t_time_w], s1_t_time_h24, s1_t_time_min, s1_t_time_sec); break; case (U4)CONDITIONTWO: /* Numeric date with Chinese weekday */ u4_t_format_ret = snprintf(u1p_a_time_bufferone, u4_a_buf_size, "格式2:%u/%u/%u %s %02u:%02u:%02u", u2_t_time_y, s1_t_time_m, s1_t_time_d, u1p_sp_TIME_WEEKZH[s1_t_time_w], s1_t_time_h24, s1_t_time_min, s1_t_time_sec); break; case (U4)CONDITIONTHREE: /* Numeric date with AM/PM */ u4_t_format_ret = snprintf(u1p_a_time_bufferone, u4_a_buf_size, "格式3:%u/%u/%u %s %u:%02u:%02u(%s)", u2_t_time_y, s1_t_time_m, s1_t_time_d, u1p_sp_TIME_WEEKZH[s1_t_time_w], s1_t_time_h24, s1_t_time_min, s1_t_time_sec, s1p_t_TIME_AMPM); break; case (U4)CONDITIONFOUR: /* English full date format */ u4_t_format_ret = snprintf(u1p_a_time_bufferone, u4_a_buf_size, "格式4:%s, %s %u, %u %02u:%02u:%02u", u1p_sp_TIME_WEEKEN[s1_t_time_w], u1p_sp_TIME_MONTHEN[s1_t_time_m - 1], s1_t_time_d, u2_t_time_y, s1_t_time_h24, s1_t_time_min, s1_t_time_sec); break; case (U4)CONDITIONFIVE: /* Japanese-style format */ u4_t_format_ret = snprintf(u1p_a_time_bufferone, u4_a_buf_size, "格式5:%u年%u月%u日(%s) %u:%02u:%02u(%s)", u2_t_time_y, s1_t_time_m, s1_t_time_d, u1p_sp_TIME_WEEKJP[s1_t_time_w], s1_t_time_h12, s1_t_time_min, s1_t_time_sec, s1p_t_TIME_AMPM); break; default: /* Handle invalid format index */ u4_t_format_ret = snprintf(u1p_a_time_bufferone, u4_a_buf_size, "[错误] 无效格式编号:%u", u1_a_format_index); break; } } return u4_t_format_ret; /* Return formatted string length */ } /* Display time in specified format */ void vd_g_time_Display_format(U1 u1_a_format_index) { SYSTEMTIME st_t_format_t; /* System time structure */ GetLocalTime(&st_t_format_t); /* Get current local time */ U1 u1_tp_format_buffer[(U4)MAX_TIME_STR]; /* Format buffer */ /* Format and print time */ u4_s_time_Format(u1_a_format_index, &st_t_format_t, u1_tp_format_buffer, sizeof(u1_tp_format_buffer)); printf("%s\n", u1_tp_format_buffer); /* Print with newline */ } /* Display all available time formats */ void vd_g_time_Display_allformats(void) { U1 u1_t_allformats_i; /* Loop counter */ /* Iterate through all format options */ for (u1_t_allformats_i = (U1)TEST_ONE; u1_t_allformats_i <= (U1)TEST_FIVE; ++u1_t_allformats_i) { vd_g_time_Display_format(u1_t_allformats_i); /* Display each format */ } } /* Write all time formats to log file */ void vd_g_time_Write_allformats_to_file(void) { FILE* stp_t_file_fp; /* File pointer */ errno_t s4_t_file_err; /* File error code */ SYSTEMTIME st_t_systemtime_t; /* System time structure */ U1 u1_t_file_i; /* Loop counter */ U1 u1_tp_file_buffer[(U4)MAX_TIME_STR]; /* Format buffer */ S4 s4_t_fclose_result; /* File close result */ /* Open log file in append mode */ s4_t_file_err = fopen_s(&stp_t_file_fp, "time_log.txt", "a"); if ((S4)TEST_ONE != s4_t_file_err || NULL == stp_t_file_fp) { printf("[错误] 无法打开 time_log.txt,错误码:%d\n", s4_t_file_err); return; } else { /* No action needed on success */ } GetLocalTime(&st_t_systemtime_t); /* Get current time */ /* Write all formats to file */ for (u1_t_file_i = 1; u1_t_file_i <= 5; ++u1_t_file_i) { u4_s_time_Format(u1_t_file_i, &st_t_systemtime_t, u1_tp_file_buffer, sizeof(u1_tp_file_buffer)); fprintf(stp_t_file_fp, "%s\n", u1_tp_file_buffer); /* Write with newline */ } /* Add separator between entries */ fprintf(stp_t_file_fp, "----------------------------------------\n\n"); /* Close file handle */ s4_t_fclose_result = fclose(stp_t_file_fp); if ((S4)TEST_ZERO != s4_t_fclose_result) { printf("[警告] 文件关闭失败\n"); /* Warn on close failure */ } else { /* No action needed on success */ } } /*===================================================================================================================================*/ /* Display Application Opening2 : Post Task */ /* --------------------------------------------------------------------------------------------------------------------------------- */ /* Arguments: U1 u1_contents : Selected Content ID in dspmgr */ /* Return: - */ /*===================================================================================================================================*/按照这个格式帮我注释函数,原来的注释不要删了
08-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值