0% found this document useful (0 votes)
27 views

Lecture No 3

Uploaded by

hafsaashraf4093
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Lecture No 3

Uploaded by

hafsaashraf4093
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

How to Compare

String in Python?
What is string?
What is string?
• Most programming languages have a data type called a
string, which is used for data values that are made up of
ordered sequences of characters, such as "hello world“
and"LKJH019283". A string can contain any sequence of
characters, visible or invisible, and characters may be repeated

• Data type is an attribute associated with a piece of data that


tells a computer system how to interpret its value
What are Strings?
• A string is generally a sequence of characters. A character is a
simple symbol. For example, in the English Language, we have
26 characters available. The computer system does not
understand characters and hence, therefore, deal with binary
numbers. Even though we can see characters on our monitor
screens, but internally it is stored and manipulated as a
combination of 0s and 1s. The conversion of characters and
the binary number is called encoding, and the reverse of this
is known as decoding. Some of the popular encodings are
ASCII and Unicode. In the Python programming language, a
string is a sequence of Unicode characters.
Unicode
Unicode supports more than a million code points, which are
written with a "U" followed by a plus sign and the number in
hex;
for example
, the word "Hello" is written
U+0048 U+0065 U+006C U+006C U+006F
The ASCII table
What is encoding and example?
• the action of transforming a message into code. 2.
computing. the action of converting (characters and symbols)
into a digital form as a series of impulses.
Encoding is the process of hearing a sound and being able to
write a symbol to represent that sound. … For example: if a
child hears the sound /t/ and then writes the letter 't', this
means they are able to encode this sound.
What is decoding and example?

• Decoding is the process of turning communication into thoughts. For


example, you may realize you're hungry and encode the following message
to send to your roommate: “I'm hungry.
• to convert (something, such as a coded message) into intelligible form. b :
to recognize and interpret (an electronic signal)
Python String Comparison operators
• In python language, we can compare two strings such as identify
whether the two strings are equivalent to each other or not, or even
which string is greater or smaller than each other. Let us check some
of the string comparison operator used for this purpose below:
• ==: This operator checks whether two strings are equal.
• !=: This operator checks whether two strings are not equal.
• <: This operator checks whether the string on the left side is smaller
than the string on the right side.
• <=: This operator checks whether the string on the left side is
smaller or equal to the string on the right side.
• >: This operator checks whether the string on the left side is greater
than the string on the right side.
• >=: This operator checks whether the string on the left side is
greater than the string on the right side.
• Exclamation mark ! colon : Underscore ___
String Equals Check in Python

• In python programming we can check whether strings are


equal or not using the “==” or by using the “.__eq__” function.
Example:
What about Case insensitive
comparisons?
• While checking the equality in strings sometimes we wish to
ignore the case of the string while comparison. So, as a
solution to this, we can use the case fold(), lower(), or upper()
function for ignoring the case insensitive comparison of string
equality.
input
The output of the above code is as given
below:
Conclusion
• So, in this article, we studied how to compare strings in a
python programming language. Also, we studied some string
comparison operators and check string equality. Even we
checked the string case insensitive comparison.

You might also like