Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
How to Find the String Length | Strings
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

bookHow to Find the String Length

I presume you might have contemplated the question: "Why should I bother calculating the character count within a string? I seek simplification..." However, Python boasts an extensive repertoire of built-in functions, and among these, determining the length of a string using len() is a fundamental and frequently employed operation in programming. Allow me to illustrate this with an example, which should elucidate the concept further:

12345
string = "Practice is the key to success" length = len(string) print("Here is the string:", string) print("And its length is", length)
copy

Note

Please take note of the len() function; it calculates the number of items within the string, which can be referred to as the string's length.

Task

Time to practice:

  1. Get the last character of the variable string using negative indexation and assign the result to the variable symbol1.
  2. Extract the index of the last character of the variable string using the len() method and assign the result to the variable symbol2.

Note that len(word) equals the length of the word, but len(word)-1 equals the index of the last character of the word.

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 3. Chapter 8
toggle bottom row

bookHow to Find the String Length

I presume you might have contemplated the question: "Why should I bother calculating the character count within a string? I seek simplification..." However, Python boasts an extensive repertoire of built-in functions, and among these, determining the length of a string using len() is a fundamental and frequently employed operation in programming. Allow me to illustrate this with an example, which should elucidate the concept further:

12345
string = "Practice is the key to success" length = len(string) print("Here is the string:", string) print("And its length is", length)
copy

Note

Please take note of the len() function; it calculates the number of items within the string, which can be referred to as the string's length.

Task

Time to practice:

  1. Get the last character of the variable string using negative indexation and assign the result to the variable symbol1.
  2. Extract the index of the last character of the variable string using the len() method and assign the result to the variable symbol2.

Note that len(word) equals the length of the word, but len(word)-1 equals the index of the last character of the word.

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 3. Chapter 8
toggle bottom row

bookHow to Find the String Length

I presume you might have contemplated the question: "Why should I bother calculating the character count within a string? I seek simplification..." However, Python boasts an extensive repertoire of built-in functions, and among these, determining the length of a string using len() is a fundamental and frequently employed operation in programming. Allow me to illustrate this with an example, which should elucidate the concept further:

12345
string = "Practice is the key to success" length = len(string) print("Here is the string:", string) print("And its length is", length)
copy

Note

Please take note of the len() function; it calculates the number of items within the string, which can be referred to as the string's length.

Task

Time to practice:

  1. Get the last character of the variable string using negative indexation and assign the result to the variable symbol1.
  2. Extract the index of the last character of the variable string using the len() method and assign the result to the variable symbol2.

Note that len(word) equals the length of the word, but len(word)-1 equals the index of the last character of the word.

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!

I presume you might have contemplated the question: "Why should I bother calculating the character count within a string? I seek simplification..." However, Python boasts an extensive repertoire of built-in functions, and among these, determining the length of a string using len() is a fundamental and frequently employed operation in programming. Allow me to illustrate this with an example, which should elucidate the concept further:

12345
string = "Practice is the key to success" length = len(string) print("Here is the string:", string) print("And its length is", length)
copy

Note

Please take note of the len() function; it calculates the number of items within the string, which can be referred to as the string's length.

Task

Time to practice:

  1. Get the last character of the variable string using negative indexation and assign the result to the variable symbol1.
  2. Extract the index of the last character of the variable string using the len() method and assign the result to the variable symbol2.

Note that len(word) equals the length of the word, but len(word)-1 equals the index of the last character of the word.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 3. Chapter 8
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
some-alt