{"id":1029,"date":"2023-03-24T09:47:07","date_gmt":"2023-03-24T01:47:07","guid":{"rendered":""},"modified":"2023-03-24T09:47:07","modified_gmt":"2023-03-24T01:47:07","slug":"Python \u6761\u4ef6\u63a7\u5236","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/1029.html","title":{"rendered":"Python \u6761\u4ef6\u63a7\u5236"},"content":{"rendered":"
\n
\u641e\u61c2Python\u7a0b\u5e8f\u6267\u884c\u4e2d\u7684\u6761\u4ef6\u63a7\u5236<\/span>\n <\/div>\n \u82e5 condition_1 \u6761\u4ef6\u6210\u7acb\uff08True\uff09\uff0c\u5c06\u6267\u884c statement_block_1 \u4e1a\u52a1\u4ee3\u7801\u5757<\/span> <\/body> <\/p>\n
<\/p>\n
\u7ed3\u6784<\/h2>\n
if<\/span> condition_1:<\/span>
statement_block_1<\/span>
elif<\/span> condition_2:<\/span>
statement_block_2<\/span>
else:<\/span>
statement_block_3<\/span>
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u82e5 condition_1 \u6761\u4ef6\u4e0d\u6210\u7acb\uff08False\uff09\uff0c\u5c06\u8df3\u8fc7 statement_block_1 \u4e1a\u52a1\u4ee3\u7801\u5757\uff0c\u8fdb\u5165\u4e0b\u4e00\u4e2a\u6761\u4ef6\u5224\u65ad<\/span>
\n \u82e5 condition_2 \u6761\u4ef6\u6210\u7acb\uff08True\uff09\uff0c\u5c06\u6267\u884c statement_block_2 \u4e1a\u52a1\u4ee3\u7801\u5757<\/span>
\n \u82e5 condition_2 \u6761\u4ef6\u4e0d\u6210\u7acb\uff08False\uff09\uff0c\u5c06 statement_block_2 \u4e1a\u52a1\u4ee3\u7801\u5757\uff0c\u8fdb\u5165\u4e0b\u4e00\u4e2a\u6761\u4ef6\u5224\u65ad<\/span> <\/p>\n
\n elif<\/b>\u662f
\n else if<\/b>\u7684\u7b80\u5199\uff0c\u6240\u4ee5if\u8bed\u53e5\u7684\u5173\u952e\u5b57\u683c\u5f0f\u4e3a\uff1a
\n if \u2013 elif \u2013 else<\/b>\u3002\n <\/div>\n <\/p>\n
\u5b9e\u4f8b<\/h2>\n
age<\/span> = 20<\/span>
if<\/span> age >= 18:<\/span>
print(\"\u606d\u559c\u4f60\uff0c\u4f60\u5df2\u7ecf\u6210\u5e74\u5566\uff5e\"<\/span>)
elif<\/span> age < 18 and age >12:<\/span>
print(\"\u606d\u559c\u4f60\uff0c\u4f60\u5df2\u7ecf\u6210\u5e74\u5566\uff5e\"<\/span>)
elif<\/span> age < 13 and age >7:<\/span>
print(\"\u4f60\u662f\u4e3a\u5c11\u513f\uff5e\"<\/span>)
else:<\/span>
print(\"\u4f60\u662f\u4e3a\u5a74\u5e7c\u513f\uff5e\"<\/span>)
<\/span><\/code><\/pre>\n<\/p><\/div>\n\u606d\u559c\u4f60\uff0c\u4f60\u5df2\u7ecf\u6210\u5e74\u5566\uff5e<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n\n
\n \u64cd\u4f5c\u7b26<\/td>\n \u63cf\u8ff0<\/td>\n<\/tr>\n \n <<\/td>\n \u5c0f\u4e8e<\/td>\n<\/tr>\n \n <= <\/td>\n \u5c0f\u4e8e\u6216\u7b49\u4e8e<\/td>\n<\/tr>\n \n ><\/td>\n \u5927\u4e8e<\/td>\n<\/tr>\n \n >=<\/td>\n \u5927\u4e8e\u6216\u7b49\u4e8e<\/td>\n<\/tr>\n \n ==<\/td>\n \u7b49\u4e8e\uff0c\u6bd4\u8f83\u4e24\u4e2a\u503c\u662f\u5426\u76f8\u7b49<\/td>\n<\/tr>\n \n !=<\/td>\n \u4e0d\u7b49\u4e8e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n if \u5d4c\u5957<\/h2>\n
if<\/span> condition_1:<\/span>
statement_block_1<\/span>
if<\/span> condition_2:<\/span>
statement_block_3<\/span>
elif<\/span> condition_3:<\/span>
statement_block_3<\/span>
else:<\/span>
statement_block_4<\/span>
elif<\/span> condition_5:<\/span>
statement_block_6<\/span>
else:<\/span>
statement_block_6<\/span>
<\/span><\/code><\/pre>\n<\/p><\/div>\n age<\/span> = 50<\/span>
if<\/span> age >= 18:<\/span>
print(\"\u606d\u559c\u4f60\uff0c\u4f60\u5df2\u7ecf\u6210\u5e74\u5566\uff5e\"<\/span>)
if<\/span> age == 50:<\/span>
print(\"\u4f60\u7684\u5e74\u9f84\u662f50\u5c81\"<\/span>)
elif<\/span> age == 40:<\/span>
print(\"\u4f60\u7684\u5e74\u9f84\u662f40\u5c81\"<\/span>)
else:<\/span>
print(\"\u4f60\u7684\u5e74\u9f84\u4e0d\u662f30\u5c81\u4e5f\u4e0d\u662f40\u5c81\"<\/span>)
elif<\/span> age < 18 and age >12:<\/span>
print(\"\u4f60\u7684\u5e74\u9f84\u572812\u5c81\u523018\u5c81\u4e4b\u95f4\"<\/span>)
else:<\/span>
print(\"\u4f60\u7684\u5e74\u9f84\u5c0f\u4e8e12\u5c81\"<\/span>) <\/span><\/code><\/pre>\n<\/p><\/div>\n\u606d\u559c\u4f60\uff0c\u4f60\u5df2\u7ecf\u6210\u5e74\u5566\uff5e
\u4f60\u7684\u5e74\u9f84\u662f50\u5c81<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"Python \u6761\u4ef6\u63a7\u5236zh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[126],"tags":[],"class_list":["post-1029","post","type-post","status-publish","format-standard","hentry","category-python3"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1029"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=1029"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1029\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=1029"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=1029"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=1029"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}