find the length of a string in python

To find the length of a string in Python, we can use the len() function which takes a string as an argument and returns its length.

Here's some sample code that demonstrates how to use the len() function:

main.py
my_str = "hello world"
print(len(my_str)) # Output: 11
55 chars
3 lines

In this code, we create a variable called my_str and initialize it with the value "hello world". We then pass my_str as an argument to len() function and print out the result which is the length of the string, 11.

related categories

gistlibby LogSnag