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
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, networking, learning, and sharing knowledge.