Get the length of a string in Python
In Python, you can get the length of a string using the len()
function.
The len() function returns the length of a string with whitespace(s)
Getting the length of a string in Python using len() function
1. Create a variable named str_variable
and assign string value "Python is fun."
to the variable.
2. Use the len(str_variable)
function to get the length of the string variable str_variable
. Assign the result to a new variable called string_length
and get the output using print() function.
Please take a closer look at the following example:
Example of using len() function
Output of the above example
The length of the string is 14