In this source code example, we will demonstrate how to find the length of the string in Python.
The len method calculates the number of characters in a string. The white characters are also counted.Python string length example
The following example computes the length of three strings. Let's create a string_length.py file and add the following content to it:#!/usr/bin/env python
# string_length.py
s1 = "SourceCodeExamples"
s2 = "SourceCodeExamples\n"
s3 = "SourceCodeExamples "
print(len(s1))
print(len(s2))
print(len(s3))
Output:
18
19
20
Related Python String Examples
- Python string literals
- Python string length example
- Python String join() method example
- Python string split() method example
- Python String index() method example
- Python string find() method example
- Python string startswith() method example
- Python string endswith() method example
- Python String lower() method example
- Python String upper() method example
- Python string title() method example
- Python string capitalize() method example
- Python string islower() method example
- Python string istitle() method example
- Python string isupper() method example
- Python string swapcase() method example
- Python string strip() method example
- Python string replace() method example
- Python string isdigit() method example
- Python string isdecimal() method example
- Python string isnumeric() method example
- Python string isalpha() method example
- Python string isalnum() method example
Comments
Post a Comment