深度阅读

How to find the length of a string in Python using the `len()` function?

作者
作者
2023年08月22日
更新时间
6.16 分钟
阅读时间
0
阅读量

Yes, you can find the length of a string in Python using the len() function. The len() function returns the number of characters in the string.

Here’s an example:

my_string = "hello, world!"
string_length = len(my_string)
print(string_length)

Output:

13

In this example, we have defined a string, and then we call the len() function on the string to get the number of characters in the string.

Note that the len() function can also be used to get the length of other data types such as lists, tuples and dictionaries which as well return the number of elements in the container.

相关标签

博客作者

热爱技术,乐于分享,持续学习。专注于Web开发、系统架构设计和人工智能领域。