0

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
2
Contributors
4
Replies
6
Views
12 Years
Discussion Span
Last Post by k_en
0

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
0

Why i got this error ?

newS = sentence.lower()
AttributeError: 'tuple' object has no attribute 'lower'
0

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?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.