Is python case sensitive when dealing with identifiers?

Safalta Expert Published by: Aryan Rana Updated Wed, 16 Nov 2022 10:44 PM IST

Highlights

A variable, function, class, module, or other object is known by its name when it is referenced in Python. An identifier often consists of one or more letters, underscores, or numerals from A to Z, or from a to z, followed by zero or more of those characters (0 to 9).

Python is case sensitive programming language as it treats uppercase and lowercase characters differently. Not only the characters it also treats the identifiers the same way. Since the language is case sensitive the user must be aware of case sensitivity while naming and assigning value to characters. You should be care ul for naming count1 and count2 if you wish to keep counts of two values. The latter would provide you with distinct variables, but over time, it might make things harder to grasp.  The space below has details on Python and case sensitivity. If you are interested in Digital Marketing or Graphic Designing and want to learn these interesting courses then click on the links mentioned Digital Marketing Course and Graphic Designing course

Source: Safalta.com



Download these FREE Ebooks:
1. Introduction to Digital Marketing
2. Website Planning and Creation

Python Identifiers: Rules


A few conditions need to be satisfied in order to generate a Python identifier.
  • Identifier names cannot contain reserved keywords (special words used for a particular purpose, such as while, for, if, etc.).
  • Lowercase characters (a–z), capital letters (A–Z), numbers (0–9), and underscores (_) are all permitted in Python IDs. As a result, Python identifiers can only contain the underscore special character.
  • No number may start with the name of the identifier.
  • A Python identifier's name may start with an underscore.
  • The identifier name's length is unconstrained.
  • Python identifier names are case-sensitive.

Free Demo Classes

Register here for Free Demo Classes


Python identifier example


You can generate identifiers in Python by using the aforementioned rules. Consider the following instances to get a better understanding of this:

Valid Identifiers


only includes letters and digits in count 1
contains all sane characters in count oddNo
_: an acceptable identifier is underscore
_count: identification may begin with an asterisk
_5: legitimate because it begins with an underscore and contains characters that are allowed.
My Dog Loves Cookies, Ham, and Cheese is still acceptable despite its length because there are no length limitations.


Invalid Identifiers

no keywords permitted for
A+B: Only underscores and other special characters are permitted.
200: An identification cannot be solely a number
Identifiers cannot start with numbers, according to 2Abs.

Best Practices for Python Identifier Naming

  • When naming identifiers for constants, use only uppercase letters.
  • In the constant name, words may be separated by underscores.
  • Examples: MAX LENGTH, SUM OF ODD, etc.
  • For class names: Python class names must begin with an uppercase letter.
  • Use camelcase, which requires that each word in an identifier start with a capital letter, to separate words and improve readability.
  • For instance, student name, mobile number, etc.
  • Individual Variables:
  • Underscores are typically used to begin Python built-in types. Except when utilising a private variable, you can avoid this.
  • Instance: _digit
  • named packages:
  • When naming packages, use lowercase.
  • Don't use underscores in your text.
  • Calculus, utilities, etc.
  •  
  • Other: Use lowercase letters for naming variables, functions, and modules. In these situations, use underscore as the separator. For instance, emp salary, is complete(), etc. If you'd want, you can also name things using camel casing. The names listed above, for instance, can be expressed as empSalary, isComplete(), etc.
  • The identifier name shouldn't include two underscores at the beginning or end. Only a keyword defined by a language can utilise such naming.
  • It is always a good idea to begin the function name with is for boolean functions. This aids in obtaining a yes/no response. Examples include is paid(), is traveling(), etc. These might be expressed as isTraveling(), isPaid(), etc. if camel case is used.

 

Related Article

CTET Answer Key 2024: दिसंबर सत्र की सीटेट परीक्षा की उत्तर कुंजी जल्द होगी जारी, जानें कैसे कर सकेंगे डाउनलोड

Read More

CLAT 2025: दिल्ली उच्च न्यायालय ने एनएलयू को दिया क्लैट परीक्षा के नतीजों में संशोधन का आदेश, जानें पूरा मामला

Read More

UP Police: यूपी पुलिस भर्ती का आवेदन पत्र डाउनलोड करने का एक और मौका, यूपीपीआरपीबी ने फिर से सक्रिया किया लिंक

Read More

JEE Advanced 2025: जेईई एडवांस्ड के लिए 23 अप्रैल से शुरू होगा आवेदन, जानें कौन कर सकता है पंजीकरण

Read More

UPSC CSE Mains 2024 Interview Schedule out now; Personality tests from 7 January, Check full timetable here

Read More

Common Admission Test (CAT) 2024 Result out; 14 Students Score 100 Percentile, Read here

Read More

CAT Result: कैट परीक्षा के परिणाम जारी, इतने उम्मीदवारों ने 100 पर्सेंटाइल स्कोर किए हासिल; चेक करें रिजल्ट

Read More

CBSE: डमी प्रवेश रोकने के लिए सीबीएसई का सख्त कदम, 18 स्कूलों को जारी किया कारण बताओ नोटिस

Read More

Jharkhand Board Exam Dates 2025 released; Exams from 11 February, Check the full schedule here

Read More