學習程序養成良好的編碼習慣
1.類名采用駝峰命名法,即類名的每個首字母都大寫,如:class HelloWord,類名不使用下劃線
# -*- coding: utf-8 -*-
# @Author : 一凡
# 單詞首字線大寫用不使用下劃線
class HelloWord():
pass
2.函式名只使用小寫字母和下劃線
# -*- coding: utf-8 -*-
# @Author : 一凡
# 函式名使用小寫
# 多個單詞中間使用下劃線
def hello_word():
pass
3.定義類后面包含一個檔案字串且與代碼空一行,字串說明也可以用雙三引號頂級定義之間空兩行
# -*- coding: utf-8 -*-
# @Author : 一凡
class HelloWord():
"""類說明檔案"""
# 處于空一行
def hello_word(self):
pass
5.兩個類之間使用兩個空行來分隔
# -*- coding: utf-8 -*-
# @Author : 一凡
class HelloWord():
"""類說明檔案"""
def hello_word(self):
pass
"""
空行
空行
"""
class HelloPython():
"""類說明檔案"""
def hello_Python(self):
pass
6.變數等號兩邊各有一個空格 a = 10
# -*- coding: utf-8 -*-
# @Author : 一凡
name = "一凡"
7.函式括號里的引數 = 兩邊不需要空格
# -*- coding: utf-8 -*-
# @Author : 一凡
def hello(name="一凡"):
pass
8.函式下方需要帶函式說明字串且與代碼空一行
# -*- coding: utf-8 -*-
# @Author : 一凡
def hello(name="一凡"):
"""函式說明檔案"""
# 與代碼段空一行
pass
9.默認引數要寫在最后,且逗號后邊空一格
# -*- coding: utf-8 -*-
# @Author : 一凡
def hello(age, name="一凡"):
"""默認引數寫在后面,如name引數"""
# 與代碼段空一行
pass
10.函式與函式之間空一行
# -*- coding: utf-8 -*-
# @Author : 一凡
def hello():
# 與代碼段空一行
pass
# 函式之間空一行
def python():
pass
11.if陳述句后的運算子兩邊需要空格
# -*- coding: utf-8 -*-
# @Author : 一凡
a = 10
# 運算子兩邊要空一格
if a == 10:
pass
12.變數名,函式名,類名等不要使用拼音
# -*- coding: utf-8 -*-
# @Author : 一凡
# 函式、變數名、類名不使用拼音
def pingyin():
pass
如果想學習軟體測驗,就快加入:893694563,群內學軟體測驗,分享技術和學習資料,陪你一起成長和學習,
點擊變數取名神網站

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/317896.html
標籤:其他
上一篇:谷歌發布 Android 12 硬體標準:6GB記憶體+1080P螢屏
下一篇:【劍指卷王】合并兩個有序陣列
