Tuesday 30 May 2023

Python: Get number of characters in a String

Using python built-in function ‘len()’, we can get the number of characters in a string.

 

no_of_chars_in_string.py

str = 'Hello World'
msg = f'"{str}" has {len(str)} characters'

print(msg)

 

Output

"Hello World" has 11 characters

 

 

 

 

Previous                                                 Next                                                 Home

No comments:

Post a Comment