首页
/
每日頭條
/
科技
/
python編程入門到精通
python編程入門到精通
更新时间:2025-11-13 21:43:06

  python編程入門到精通(大亭碎碎念六)(1)

  python編程入門到精通(大亭碎碎念六)(2)

  分享興趣,傳播快樂,增長見聞,留下美好!

  親愛的您,這裡是Learning Yard學苑。

  今天大亭為大家帶來我的“python編程規範”,

  歡迎您的訪問!

  Share interest,spread happiness ,

  increase knowledge and leave beautiful.

  Dear you,this is the Learing Yard Academy!

  Today, Dating will brings you “The Programming specifications of Python”,Welcome your visit!

  一、縮進

  縮進并不隻是為了美觀,也不僅僅為了增加可讀性。每個縮進級别應采用 4 個空格。連續行所包裝的元素應該要麼采用 Python 隐式排列,即垂直對齊于圓括号、方括号和花括号,要麼采用懸挂縮進,而在采用懸挂縮進時需考慮:第一行不應該包括參數,并且在續行中需要再縮進一級以便清楚表示,懸挂縮進可以不采用4空格的縮進方法。

  Indentation is not only for aesthetic purposes, but also for readability. Each indent level should have 4 spaces. The elements packed by consecutive lines should either be arranged implicitly in Python, that is, vertically aligned with parentheses, square brackets and curly brackets, or be indented by hanging. When adopting hanging indent, it is necessary to consider that the first line should not include parameters, and the continued lines need to be indented one more level for clear indication. Hanging indent can not adopt the indent method of four spaces.

  多行結束右圓/方/花括号可以單獨一行書寫,和上一行的縮進對齊,也可以和多行開始的第一行的第一個字符對齊,但不可以和上一行最後一個字符對齊。推薦的換行方式是利用 Python 圓括号、方括号和花括号中的隐式續行。很長的行可以通過在括号内換行來分成多行,最好加上反斜杠來區别續行。

  The right circle/square/curly bracket at the end of multiple lines can be written on a single line, aligned with the indent of the previous line, or aligned with the first character of the first line at the beginning of multiple lines, but not with the last character of the previous line. The recommended line breaking method is to use the implicit line continuation in Python parentheses, square brackets, and curly brackets. Long lines can be divided into multiple lines by wrapping them in parentheses. It is better to add a backslash to distinguish continuation lines.

  二、導入函數

  導入應該寫在代碼文件開頭,位于模塊注釋和文檔字符串之後,模塊全局變量和常量聲明之前。應該按照下面的順序分組來寫:标準庫imports-相關第三方imports-本地應用/庫的特定imports,不同組的導入之間用空格隔開。常見有三種導入方法:第一種是import模塊名,使用這種方法導入,如果模塊名很長可以使用[as别名];第二種是from模塊名import對象名,同樣的在使用時可以給模塊名起别名;第三種是from 模塊名 import *,但這種方法簡單粗暴,一下子導入所有内容,會降低可讀性,如果多個模塊中有同名對象,之前導入的同名對象全部無法訪問,僅最後導入的模塊中的對象有效,不利于代碼的後期維護。

  The import should be written at the beginning of the code file, after the module comments and document strings, and before the module global variables and constants declaration. It should be written in the following order: standard library imports - related third-party imports - specific imports of local applications/libraries. The imports of different groups should be separated by spaces. There are three common import methods: the first is to import the module name. If the module name is very long, you can use [as alias]; The second is from module name import object name, which can also be aliased when used; The third method is from module name import *. However, this method is simple and crude. Importing all content at once will reduce readability. If there are objects with the same name in multiple modules, all previously imported objects with the same name cannot be accessed. Only the objects in the last imported module are valid, which is unfavorable for later code maintenance.

  今天的分享就到這裡了,

  如果您對文章有獨特的想法,歡迎給我們留言。

  讓我們相約明天,祝您今天過得開心快樂!

  Thats it for todays sharing. If you have a unique idea about the article.please leave us a message.

  Let us meet tomorrow I wish you a happy day today!

  參考資料:百度

  翻譯來源:百度翻譯

  聲明:本文由LearningYard新學苑原創,如有侵權,請聯系删除!

  END

  文案|雷雅婷

  排版|雷雅婷

  審核|闫慶紅

  ,

Comments
Welcome to tft每日頭條 comments! Please keep conversations courteous and on-topic. To fosterproductive and respectful conversations, you may see comments from our Community Managers.
Sign up to post
Sort by
Show More Comments
推荐阅读
儲存卡如何下載應用
儲存卡如何下載應用
1、點開手機設置,找到自己的應用程序管理。2、點開應用程序之後,選擇自己想要移動的應用,下面我就用高德地圖”給大家演示。3、點開高德地圖”後,點擊儲存”這時候會顯示手機内存的總量以及該軟件所占的内存量。4、點開儲存之後點擊更改”,地下還有清除數據,如果自己的軟件數據太多且有不需要的數據,就可以點擊清除,來清除數據。5、點擊更改之後,會彈出一個更改位置的提示框,點擊選擇sd卡,這樣就可以等待系統導出
2025-11-13
筆記本bios怎麼恢複出廠設置
筆記本bios怎麼恢複出廠設置
演示機型:華為MateBookX系統版本:win101、需要将電腦重啟,然後在開機界面快速的按“F2”,就會進入BIOS菜單。2、在BIOS界面,按鍵盤左右方向鍵選中Exlt,接着再按下方向鍵來進入選擇。3、需要在“Exlt”菜單中選擇“LoadDefaultSettings”,即可完成恢複出廠設置的操作。4、最後按鍵盤上的&
2025-11-13
國三柴油車2020年還能審嗎
國三柴油車2020年還能審嗎
1、國三汽車2020年正常還能年審的,不過一些大城市的市區主要區域,國三汽車有可能會被限行的。2、目前柴油車年檢已增加氮氧化物排放檢驗,這無疑是增加了年檢難度。甚至有地方已開始停止對國三車的年檢。如果到了2021年,全國所有重型柴油車均要符合國六标準,國三車再要過年檢幾乎不可能。3、因為目前國六标準還未涉及到重型柴油貨車,所以國三車并沒有要求強制報廢而是引導報廢。為了鼓勵國三車能提前報廢,不少地區
2025-11-13
學生黨買得起的旗艦手機有哪些
學生黨買得起的旗艦手機有哪些
1、華為p30。作為一個國内巨頭,華為必須是一流的。它擁有6.1英寸的屏幕和1080p的高清分辨率,在屏幕顯示方面擊敗了86.24%的手機。屏幕類型是一個完整的水滴屏幕,使屏幕看起來更大,更有視覺吸引力。電池容量3650mah,30分鐘充電62%。玻璃機身用于外部,使機身看起來更有質感。攝像頭的配置是後攝三攝,前面是3200萬像素,後面是4000萬+1600萬+800萬像素,攝像頭功能并不遜色于i
2025-11-13
電腦微信怎麼找删除好友
電腦微信怎麼找删除好友
1、登錄微信帳号,需要手機确認登錄的微信。2、登錄好後确認要删除的人是哪位。3、然後去聯系人那裡,圖...
2025-11-13
Copyright 2023-2025 - www.tftnews.com All Rights Reserved