988 B
988 B
title | tags | aliases | ||||||
---|---|---|---|---|---|---|---|---|
len() |
|
|
[!note] Concept
Thelen()
function returns the number of characters in a string (including spaces and punctuation).[!example] Example
len('hello') # 5 len('My very energetic monster just scarfed nachos.') # 46 len('') # 0 name = "Alice" print("The length of your name is:") print(len(name)) # 5
[!important] Best Practices
len()
always returns an integer.- You must convert the result to a string when concatenating:
print("I am " + str(29) + " years old.") # OK
- Mixing integers and strings with
+
will raise aTypeError
.[!info] Related Notes
functions
typeConversions
expressions
pythonSyntaxOverview