[Python] object (including class, function) naming method

Dry goods first, general:
letters: A-Z a-z
underscores: _
numbers: 0-9(note: numbers cannot be at the beginning)

Examples of legal names

abcdef	GoodCoder	AD_fhrygfuigfr
A_a_007	__NAME123	_P_T_
_123456	Cc_Dd	_

Examples of illegal names

666Code	C++	1+1=2	(5)4
654ty54F	0.123	[email protected]
ccf-csp		atcoder&codeforces

Naming style

The first letter is generally lowercase (except for classes).
Since there can be no spaces in the object name, there are two styles:

helloWorldStr = 'Hello World'
hello_world_str = 'Hello World'
  1. Name helloWorldStr, hellocapitalize the first letter of each word (except the first one );
  2. Name it hello_world_strand add an underscore ( _) between every two words .

There are two styles, which one do you prefer?

Special case: class

for example:

class LikeTVPerson:
	def watchTV():
		print('WATCHING TV...')

LikeTVPersonlikeCapitalize the first letter of each word (the first one is no exception).

Guess you like

Origin blog.csdn.net/write_1m_lines/article/details/105645793