Python Forum
Probelm using Boolean input phrase.isupper()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Probelm using Boolean input phrase.isupper()
#1
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.
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
show code
Reply
#4
(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\"")
Reply
#5
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"
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using string input for boolean tronic72 3 695 Nov-01-2023, 07:48 AM
Last Post: Gribouillis
  user input producing incorrect boolean al_Czervik 4 3,081 Mar-05-2020, 09:50 PM
Last Post: al_Czervik
  Reverse order of phrase Error ilondire05 4 2,501 Aug-29-2019, 04:19 PM
Last Post: buran
  length constraint on phrase hash to password javaben 0 1,915 Aug-21-2019, 05:34 PM
Last Post: javaben
  Finding exact phrase in list graham23s 2 2,900 Mar-13-2019, 06:47 PM
Last Post: graham23s
  phrase loop and character comparision shiro26 6 4,079 Jul-06-2018, 02:03 AM
Last Post: shiro26
  Probelm in displaying char. indexwise ShailendraRaghunathPhadke 5 4,563 Feb-09-2017, 09:00 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020