Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Compare Strings | Bring All the Topics Together
Data Types in Python
course content

Course Content

Data Types in Python

Data Types in Python

1. Getting Familiar With Numbers in Python
2. True or False?
3. Strings
4. Bring All the Topics Together

bookCompare Strings

This chapter encompasses two distinct subjects: strings and boolean statements. The syntax we will cover here can prove quite valuable and significantly reduce the complexity of your code.

As I previously mentioned, operators such as >, <, ==, >=, and <= can be quite efficient. Now, let's explore how they can be applied to strings.

Let's start with the simplest one: ==. This compares two statements and returns True if they are equal the same way with strings:

12
print("Kate" == "Katty") print("Katty" == "Katty")
copy

In the first case, the names are different, but in the second they are completely equal. It's not a piece of brand-new information; therefore, let's move on to the other signs. As you may recall, X > Y means that X is greater than Y. But what can we say about the following operation?

1
print('A' < 'B')
copy

The expression means True because B is greater than A, but how can string be greater?

Note

There is a singular method for comparing letters according to their alphabetical order. This implies that within the alphabet, the letter B is considered greater than A as it is positioned further along. To organize items alphabetically or to perform personal assessments, you can utilize the > and < symbols.

By the way, we can compare even words. The algorithm of comparing is the following: It compares words by the first letters that differ:

1
print("alphabet" > "although")
copy

Explanation: The first two letters are equal, so comparing starts from the third letter in each word (the first unequivalent letter).

Task
test

Swipe to show code editor

To achieve resounding success you need to practice. 🤓 Your task here is to put the > or < sign to receive a True or False statement ( hint, the alphabet was attached):

  1. False in the first statement.
  2. False in the second statement.
  3. True in the third statement.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 4. Chapter 7
toggle bottom row

bookCompare Strings

This chapter encompasses two distinct subjects: strings and boolean statements. The syntax we will cover here can prove quite valuable and significantly reduce the complexity of your code.

As I previously mentioned, operators such as >, <, ==, >=, and <= can be quite efficient. Now, let's explore how they can be applied to strings.

Let's start with the simplest one: ==. This compares two statements and returns True if they are equal the same way with strings:

12
print("Kate" == "Katty") print("Katty" == "Katty")
copy

In the first case, the names are different, but in the second they are completely equal. It's not a piece of brand-new information; therefore, let's move on to the other signs. As you may recall, X > Y means that X is greater than Y. But what can we say about the following operation?

1
print('A' < 'B')
copy

The expression means True because B is greater than A, but how can string be greater?

Note

There is a singular method for comparing letters according to their alphabetical order. This implies that within the alphabet, the letter B is considered greater than A as it is positioned further along. To organize items alphabetically or to perform personal assessments, you can utilize the > and < symbols.

By the way, we can compare even words. The algorithm of comparing is the following: It compares words by the first letters that differ:

1
print("alphabet" > "although")
copy

Explanation: The first two letters are equal, so comparing starts from the third letter in each word (the first unequivalent letter).

Task
test

Swipe to show code editor

To achieve resounding success you need to practice. 🤓 Your task here is to put the > or < sign to receive a True or False statement ( hint, the alphabet was attached):

  1. False in the first statement.
  2. False in the second statement.
  3. True in the third statement.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 4. Chapter 7
toggle bottom row

bookCompare Strings

This chapter encompasses two distinct subjects: strings and boolean statements. The syntax we will cover here can prove quite valuable and significantly reduce the complexity of your code.

As I previously mentioned, operators such as >, <, ==, >=, and <= can be quite efficient. Now, let's explore how they can be applied to strings.

Let's start with the simplest one: ==. This compares two statements and returns True if they are equal the same way with strings:

12
print("Kate" == "Katty") print("Katty" == "Katty")
copy

In the first case, the names are different, but in the second they are completely equal. It's not a piece of brand-new information; therefore, let's move on to the other signs. As you may recall, X > Y means that X is greater than Y. But what can we say about the following operation?

1
print('A' < 'B')
copy

The expression means True because B is greater than A, but how can string be greater?

Note

There is a singular method for comparing letters according to their alphabetical order. This implies that within the alphabet, the letter B is considered greater than A as it is positioned further along. To organize items alphabetically or to perform personal assessments, you can utilize the > and < symbols.

By the way, we can compare even words. The algorithm of comparing is the following: It compares words by the first letters that differ:

1
print("alphabet" > "although")
copy

Explanation: The first two letters are equal, so comparing starts from the third letter in each word (the first unequivalent letter).

Task
test

Swipe to show code editor

To achieve resounding success you need to practice. 🤓 Your task here is to put the > or < sign to receive a True or False statement ( hint, the alphabet was attached):

  1. False in the first statement.
  2. False in the second statement.
  3. True in the third statement.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

This chapter encompasses two distinct subjects: strings and boolean statements. The syntax we will cover here can prove quite valuable and significantly reduce the complexity of your code.

As I previously mentioned, operators such as >, <, ==, >=, and <= can be quite efficient. Now, let's explore how they can be applied to strings.

Let's start with the simplest one: ==. This compares two statements and returns True if they are equal the same way with strings:

12
print("Kate" == "Katty") print("Katty" == "Katty")
copy

In the first case, the names are different, but in the second they are completely equal. It's not a piece of brand-new information; therefore, let's move on to the other signs. As you may recall, X > Y means that X is greater than Y. But what can we say about the following operation?

1
print('A' < 'B')
copy

The expression means True because B is greater than A, but how can string be greater?

Note

There is a singular method for comparing letters according to their alphabetical order. This implies that within the alphabet, the letter B is considered greater than A as it is positioned further along. To organize items alphabetically or to perform personal assessments, you can utilize the > and < symbols.

By the way, we can compare even words. The algorithm of comparing is the following: It compares words by the first letters that differ:

1
print("alphabet" > "although")
copy

Explanation: The first two letters are equal, so comparing starts from the third letter in each word (the first unequivalent letter).

Task
test

Swipe to show code editor

To achieve resounding success you need to practice. 🤓 Your task here is to put the > or < sign to receive a True or False statement ( hint, the alphabet was attached):

  1. False in the first statement.
  2. False in the second statement.
  3. True in the third statement.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 4. Chapter 7
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt