×

Is Python Case Sensitive

Case sensitivity is the mode of dealing with the written alphabet. The cases of the alphabet are examined and based on these words are being treated. The uppercase and lowercase letters or characters are considered dissimilar ways.

E.g. - ADMINISTRATION and administration are considered different words in any case-sensitive platform. The former contains all uppercase characters while the latter contains all lowercase characters.

It means we cannot enter and use uppercase and lowercase letters or characters interchangeably. Nowadays, the case sensitivity feature is widely being used. Passwords, email addresses, etc. are case sensitive.

In Computer World, the case sensitivity feature is becoming popular. Many Programming languages are sensitive to cases. C, C++, JAVA, RUBY, and PYTHON are their examples. JavaScript which is a scripting language is also case sensitive.

Some languages are case unresponsive. FORTRAN, BASIC, PASCAL, and PHP (scripting language used in web development) are some of them. The case of character does not affect them.

There exists a standard code UNICODE (Universal Character Encoding) for every character existing today.

They too assign separate codes for lowercase and uppercase alphabet.

Let’s dive deeper into understanding case sensitivity in python.

PYTHON is one of the popular case-sensitive programming languages. It means it treats two words written in different cases differently.

BONJOUR and bonjour are interpreted differently. Here, the case of each character is different from the others.

Bonjour and bonjour are interpreted in python differently. Even the difference in one character creates a vast difference.

Python checks characters present at the same index in both strings. It compares the Unicode values of the character starting with index 0 to the last index. After comparison, it returns the precise boolean value as per the used operator.

Illustration –

  1. print ("Civil" == " Civil " )
    Output- True
    Since UNICODE values of both words are the same.
  2. print ("civil  " < " Civil " )
    Output- True
    Since the UNICODE value of B is more than b
  3. print ("civil " > " Civil " )
    Output- False
    Since the UNICODE value of b is less than B
  4. print ("Civil " != " Civil " )
    Output- True
    Since UNICODE values of both words are different.

    There are a set of predefined rules in programming languages that are to be kept in mind to avoid an error.

The function name should always begin with a lowercase character. If the function name contains multiple words, then they can be separated with an underscore.  

A variable name cannot start with an uppercase character.

Example 1

Function1( ) {
int Ar;
}

Explanation: The snippetwritten above will produce an error as the naming convention has been violated.

Example 2

Function1( ) {
int Ar;
}

Explanation: The codewritten here will not produce an error as the naming convention has not been violated.

Illustration of case sensitivity issue

# problem with variable names of different cases


emp_first_name = 'Jessica' 
emp_last_name = 'Ted'
print ('My name is ' + emp_First_Name + ' ' + EMP_last_Name )

OUTPUT: 

Is Python Case Sensitive

Explanation: This code results in an error.

The called variables are emp_First_Name and EMP_last_Name

The declared variables are emp_first_name and emp_last_name

The cases of the above variables do not match.

# resolving the case sensitivity problem when variable names of different cases are used
 emp_first_name = 'Jessica'
 emp_last_name = 'Ted' 
print ('Employee name is ' + emp_first_name + ' ' + emp_last_name )

OUTPUT –

Is Python Case Sensitive

Explanation: This code works correctly and produces the desired output.

In Python, there are some functions to escape the case problem.

.lower( ) - This function can be taken into account to convert all uppercase characters into equivalent lowercase characters.

.upper( ) – This function can be taken into account to convert all lowercase characters into equivalent uppercase characters.

Illustration of the above functions –

# String comparison using .lower( ) function


str1 = ' PYTHON is an interesting programming language' 
str2 = ' python is an interesting programming language' 
evaluation = str1.lower() == str2 
print(evaluation)

OUTPUT:

Is Python Case Sensitive

Explanation: Upper case PYTHON in str1 gets converted into lowercase python thus both become equal and there exists no difference between them.

#String comparison using .upper( ) function
str1 = ' JAVA is an interesting programming language' 
str2 = ' JAVA is an interesting programming language' 
evaluation = ( str1.upper() == str2 )
print(evaluation)


OUTPUT:

Is Python Case Sensitive

Explanation: Lower case PYTHON in str1 gets converted into uppercase python thus both become equal and there exists no difference between them.


Related Topics

Python Compiler

What is Compiler? The compiler is mainly a program used to convert the source code into the machine or binary code. The source code is generally a computer program written using...

6 minutes read.

How to convert Float to Int in Python?

A float value can be converted to an int via type conversion, an explicit method of transforming an operand to a certain type. But it must be noted that such...

3 minutes read.

Poolmanager in Python

Python: Python is an interactive and more accessible language than any other programming language. The python programming language uses a variety of libraries to perform the operations in a faster way....

4 minutes read.

Python Recursion

Recursion is one of the most interesting yet important concepts of any programming language. If you want to be a good programmer or data scientist, then you should better have...

4 minutes read.

Python range() function

Python range() function The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified number. Syntax range(stop)        or range(start, stop[, step]) Parameter start: It is...

1 minute read.

Python Random shuffle( ) method

The shuffle() is used to change the positions of the elements in the mutable sequences. The shuffle( ) function will change the positions of the elements in the sequence of...

3 minutes read.

Python GUI Programming

GUI (Graphical User Interface) GUI is a graphics-based operating system that uses icons and menus to interact with the user. Python mostly works on CLI (Command Line Interface). Widgets Any user interface has...

4 minutes read.

Python Online Compiler

Compose, Run and Offer Python code internet involving OneCompiler's Python online compiler free of charge. It's one of the hearty, highlight-rich web-based compilers for python language, supporting both the adaptations, which...

3 minutes read.

Python List remove() method

Python List remove() method The list.remove () method in Python removes the item at the specified position in the given list. Syntax list.remove(x) Parameter x: This parameter represents the element you want to remove and accepts any type...

1 minute read.

How to Install Scikit-Learn

Sklearn or Scikit-learn is a python library used for machine learning. It contains many features like classification, regression, clustering, and Dimensionality reduction algorithms. Sklearn is used to build machine learning...

3 minutes read.

Python Variables, Constants and Literals

Python is today's most valuable, easy-to-implement and sought-out programming language. Nowadays, developers want to focus on implementing the program rather than spending time with complex programs. So, for this reason,...

17 minutes read.

GUI Calendar using Tkinter in Python

GUI: A graphical interface (GUI) is a user interface that lets users interact with electronic devices like computers and smartphones by using menus, icons, and other visual cues (graphics). In contrast...

3 minutes read.

Anonymous/Lambda Function in Python

Lambda keyword is used to declare an Anonymous function, i.e. a function that does not have any name. It is also called Anonymous functions. In python, normal functions are defined...

3 minutes read.

_name_ in Python

Introduction: The code at level 0 indentation is to be performed when the command to run a Python program is supplied to the interpreter because Python does not have a main() function...

4 minutes read.

How to Define a Function in Python?

What is a Function? In programming, a piece of code that executes a specific task or a group of related operations is known as a function. What does Python Functions Do? If you...

6 minutes read.

Conditional Expressions in Python

In Python conditional expression are sometimes referred to operator called as ternary operator. Not only Python supports ternary operator but many other programming languages supports it. Ternary operator are the...

2 minutes read.

Python enumerate() function

Python enumerate() function The enumerate() function in Python takes a collection (e.g. a tuple) and returns it as an enumerate object. Syntax: enumerate(iterable, start=0) Parameter Iterable:  This parameter represents an iterable object start:    This parameter represents a number defining...

1 minute read.

Data Drop in Python

Introduction You'll understand how to delete a group of rows from a Pandas dataframe in this article.You can read this article on How to Drop Columns in Pandas to find out...

6 minutes read.

Reverse a Number in Python

Python is an Object-Oriented high-level language. Python has an English-like syntax, which is very easy to read and write codes. Python is an interpreted language which means that it uses...

4 minutes read.

Python Project Ideas

One of the most widely used programming languages today is Python. This pattern appears set to continue through 2023 and beyond. Therefore, working on some current Python project ideas is the...

10 minutes read.