{"id":243951,"date":"2022-06-15T09:31:27","date_gmt":"2022-06-15T01:31:27","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=243951"},"modified":"2022-05-29T17:33:51","modified_gmt":"2022-05-29T09:33:51","slug":"python-self-weighr","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/python-self-weighr.html","title":{"rendered":"\u8be6\u7ec6\u4ecb\u7ecdPython\u7c7b\u7684\u7ee7\u627f\u4e0e\u591a\u6001"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u5927\u5bb6\u597d\uff0c\u672c\u7bc7\u6587\u7ae0\u4e3b\u8981\u8bb2\u7684\u662fPython\u7c7b\u7684\u7ee7\u627f\u4e0e\u591a\u6001\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u611f\u5174\u8da3\u7684\u540c\u5b66\u8d76\u5feb\u6765\u770b\u4e00\u770b\u5427\uff0c\u5bf9\u4f60\u6709\u5e2e\u52a9\u7684\u8bdd\u8bb0\u5f97\u6536\u85cf\u4e00\u4e0b\uff0c\u65b9\u4fbf\u4e0b\u6b21\u6d4f\u89c8<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \u6982\u5ff5<\/strong><\/div>\n \u7c7b(Class): \u7528\u6765\u63cf\u8ff0\u5177\u6709\u76f8\u540c\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u7684\u5bf9\u8c61\u7684\u96c6\u5408\u3002<\/p>\n \u7c7b\u53d8\u91cf\uff1a\u7c7b\u53d8\u91cf\u5728\u6574\u4e2a\u5b9e\u4f8b\u5316\u7684\u5bf9\u8c61\u4e2d\u662f\u516c\u7528\u7684\u3002\u7c7b\u53d8\u91cf\u5b9a\u4e49\u5728\u7c7b\u4e2d\u4e14\u5728\u51fd\u6570\u4f53\u4e4b\u5916\u3002\u7c7b\u53d8\u91cf\u901a\u5e38\u4e0d\u4f5c\u4e3a\u5b9e\u4f8b\u53d8\u91cf\u4f7f\u7528\u3002<\/p>\n \u7c7b\u6709\u4e00\u4e2a\u540d\u4e3a __init__() \u7684\u7279\u6b8a\u65b9\u6cd5\uff08\u6784\u9020\u65b9\u6cd5\uff09\uff0c\u8be5\u65b9\u6cd5\u5728\u7c7b\u5b9e\u4f8b\u5316\u65f6\u4f1a\u81ea\u52a8\u8c03\u7528<\/p>\n self:self \u4ee3\u8868\u7684\u662f\u7c7b\u7684\u5b9e\u4f8b\uff0c\u4ee3\u8868\u5f53\u524d\u5bf9\u8c61\u7684\u5730\u5740\uff0c\u800c self.class \u5219\u6307\u5411\u7c7b\u3002<\/p>\n \u7c7b\u8c03\u7528 Car.weight<\/p>\n \u5b9e\u4f8b\u5316 car01=Car(5)<\/p>\n \u5b9e\u4f8b\u5bf9\u8c61\u8c03\u7528 car01.weght<\/p>\n \u7c7b\u7684\u521b\u5efa<\/strong><\/div>\n #\u521b\u5efa\u5c0f\u6c7d\u8f66\u7c7b\u548c\u5ba2\u8f66\u7c7b\r\nclass Car(object):\r\n def __init__(self,weight): #\u5b9e\u4f8b\u5316\u5bf9\u8c61\u65f6\u4f20\u5165\u7279\u6709\u5c5e\u6027\r\n self.weight=weight\r\n print(\"\u5c0f\u6c7d\u8f66\")\r\n print(weight,\"t\") #\u5b9a\u4e49\u7c7b\u5185\u65b9\u6cd5\uff0c\u529f\u80fd\u662f\u6253\u5370\u51fa\u5b9e\u4f8b\u5316\u7684\u5c0f\u6c7d\u8f66\u7684\u91cd\u91cf\r\n def func(self):\r\n print(\"\u5c0f\u6c7d\u8f66\u7684\u9a7e\u9a76\u65b9\u6cd5\")\r\nclass Passenger_car(object):\r\n def __init__(self,weight):\r\n self.weight=weight\r\n print(\"\u5ba2\u8f66\")\r\n print(weight,\"t\")\r\n def func(self):\r\n print(\"\u5ba2\u8f66\u7684\u9a7e\u9a76\u65b9\u6cd5\")<\/pre>\n |