Python Forum

Full Version: Probelm using Boolean input phrase.isupper()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I'm a beginner using python. I am using version 3.5 with IDLE for version 3.5. I can use the input phrase.upper() just fine. However, according to a video I watched, I should be able to use the input phrase.isupper() also. When I try to print this, I get a mess age that says the following:

TypeError: unsupported operand type(s) for +: 'bool' and 'str'

Does anyone know what I'm doing wrong? I would be grateful for any help.
The upper method returns a new version of the string all in upper case. The isupper method checks to see if the string is already all in upper case, and returns True if it is, False if it isn't. True and False are both of type bool.
show code
(Nov-04-2018, 03:03 AM)ichabod801 Wrote: [ -> ]The upper method returns a new version of the string all in upper case. The isupper method checks to see if the string is already all in upper case, and returns True if it is, False if it isn't. True and False are both of type bool.

(Nov-04-2018, 03:03 AM)Larz60+ Wrote: [ -> ]show code

Here is the code I enter:

hominid_1 = "Ramapithecus"
hominid_2 = "Radamanthus"

phrase = "When " + hominid_1 + " sleeps,"
print (phrase.isupper() + " " + hominid_2 + "\n" " \"awakes\"")
You want to use upper(), not isupper(), isupper() is a query
Also, If you are using python 3.6 or newer, you can use f=string:
hominid_1 = "Ramapithecus"
hominid_2 = "Radamanthus"

phrase = f'when {hominid_1} sleeps'.upper()
print(f'{phrase} {hominid_2}\n"awakes"')
results:
Output:
WHEN RAMAPITHECUS SLEEPS Radamanthus "awakes"