0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Python】関数名&変数名のルール

Last updated at Posted at 2023-08-06

関数名&変数名のルールについて

関数名&変数名のルールについてアウトプットしていきたいと思います!

①先頭はアルファベット「a~z」または「A~Z」または「_(アンダースコア)」

②先頭に数字は使えない。例

OK
test             # 頭文字小文字
test_answer      # アンダースコア
Test             # 頭文字大文字
test5            # 文字の後ろに数字
NG
5test            # 頭文字に数字は使えない

③予約語も使えません(2023.8現在まで35個ある)

False, None ,True ,and ,as ,assert ,async, await, break
class, continue, def, del, elif, else ,except ,finally
for, from, global, if, import, in, is, lambda, nonlocal
not, or, pass, raise, return, try, while, with, yield

ちなみにこれで検索できます。

予約語検索の仕方
import keyword

arr = keyword.kwlist

arr.sort()

for a in arr:
	print(a)

これでもできます。

予約語検索part2
import keyword

print(keyword.kwlist)

単語構成について

①スネークケース

2単語の間に「_(アンダースコア)」でつないだもの。
pythonの変数名、関数名は英小文字スネークケース
定数名は英大文字スネークケースにします。

スネークケース
snake_case          # 変数名&関数名は、小文字
SNAKE_CASE          # 定数名は、大文字

③パスカルケース

頭文字が大文字で始まる。
Pythonではクラス名をパスカルケースにします。

パスカルケース
PascalCase          # クラス名、頭文字を大文字

Pythonでは使わないケース

②キャメルケース(Pythonでは使わない)

頭文字が小文字で始まる
小文字で始まる言語を推奨しているものがある
注意 ※Pythonでは使わない

キャメルケース
camelCase          # 最初の1文字目小文字、2単語目で大文字

④ケバブケース(Pythonでは使わない)

単語の間に「-(ハイフン)」を入れるもの。
注意 ※Pythonでは使わない。

ケバブケース
kebab-case          # kebabcaseに「-(ハイフン)」 を入れる

※なお、複数人でプロジェクト開発をする場合は、コーディング規約を確認してください。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?