Detailed Print – CSKC
Sign In

Search

siteicon
Code Learning#PYTHON#8168 Back

understanding identifiers

There are some rules to name identifiers, which are used for variable names, function names, class names etc. For time being understand some basic rules.

Source Code

		 

Click to open popup

Run Output

1 2 3 4 5 6

Notes

  • Identifier of any length
  • Only alphabets, numbers (not in beginning) or underscore allowed
  • No other special characters allowed
  • Can not use keywords (like for, while etc)
  • Names are case-sensitive. (ABC, aBc, Abc are all different names)
  • Camelcase (first letter of first word lowercase, first letter of subsequent word uppercase) type ย  for variable and function names,ย  examples: var, myVar, my_var
  • Title case (first letter of all words uppercase) for class name: ย  e.g. MyClass, My_Class
  • Most pre-defined function names can be used as value identifiers, but it should be avoided to keep away from confusion. For. eg. input can be used as an identifier, but it should be avoided.
  • Identifier rules of python keep getting updated as its new versions are released. It does support identifier names in other languages other than english with the help of unicode support.ย 
  • Identifier naming convention of python can be referred at PEP8 Style Guide.