Do anyone know why i got this error ? Do i have to import anything in order to use string.lower() & string.upper() ?
sentence = "how are you"
newS = string.lower(sentence)
NameError: name 'string' is not defined
Do anyone know why i got this error ? Do i have to import anything in order to use string.lower() & string.upper() ?
sentence = "how are you"
newS = string.lower(sentence)
NameError: name 'string' is not defined
Jump to PostThere are two ways to do this ...
# older way, needs to import string module import string sentence = "HOW ARE YOU" newS = string.lower(sentence) print newS # newer way, no import needed newerS = sentence.lower() print newerS
There are two ways to do this ...
# older way, needs to import string module
import string
sentence = "HOW ARE YOU"
newS = string.lower(sentence)
print newS
# newer way, no import needed
newerS = sentence.lower()
print newerS
Why i got this error ?
newS = sentence.lower()
AttributeError: 'tuple' object has no attribute 'lower'
The only way I can recreate this error is to make variable sentence a tuple ...
#sentence = "HOW ARE YOU"
sentence = 'HOW', 'ARE', 'YOU'
newS = sentence.lower()
print newS
Are you using an older version of Python?
Thank You.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.
You're trying to visit a URL that doesn't currently exist on the web. Most likely, a member posted a link a long time ago to a web page that has since been removed. It's also possible that there was a typo when posting the URL. We redirect you to this notice instead of stripping out the link to preserve the integrity of the post.