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'
- Name
helloWorldStr
,hello
capitalize the first letter of each word (except the first one ); - Name it
hello_world_str
and 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...')
LikeTVPerson
like
Capitalize the first letter of each word (the first one is no exception).