Course Content
Data Types in Python
Data Types in Python
How 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:
string = "Practice is the key to success" length = len(string) print("Here is the string:", string) print("And its length is", length)
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.
Swipe to show code editor
Time to practice:
- Get the last character of the variable
string
using negative indexation and assign the result to the variablesymbol1
. - Extract the index of the last character of the variable
string
using thelen()
method and assign the result to the variablesymbol2
.
Note that len(word)
equals the length of the word, but len(word)-1
equals the index of the last character of the word.
Thanks for your feedback!
How 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:
string = "Practice is the key to success" length = len(string) print("Here is the string:", string) print("And its length is", length)
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.
Swipe to show code editor
Time to practice:
- Get the last character of the variable
string
using negative indexation and assign the result to the variablesymbol1
. - Extract the index of the last character of the variable
string
using thelen()
method and assign the result to the variablesymbol2
.
Note that len(word)
equals the length of the word, but len(word)-1
equals the index of the last character of the word.
Thanks for your feedback!
How 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:
string = "Practice is the key to success" length = len(string) print("Here is the string:", string) print("And its length is", length)
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.
Swipe to show code editor
Time to practice:
- Get the last character of the variable
string
using negative indexation and assign the result to the variablesymbol1
. - Extract the index of the last character of the variable
string
using thelen()
method and assign the result to the variablesymbol2
.
Note that len(word)
equals the length of the word, but len(word)-1
equals the index of the last character of the word.
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:
string = "Practice is the key to success" length = len(string) print("Here is the string:", string) print("And its length is", length)
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.
Swipe to show code editor
Time to practice:
- Get the last character of the variable
string
using negative indexation and assign the result to the variablesymbol1
. - Extract the index of the last character of the variable
string
using thelen()
method and assign the result to the variablesymbol2
.
Note that len(word)
equals the length of the word, but len(word)-1
equals the index of the last character of the word.