Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Method not regocnized
#1
Hello Everyone,

I started learning Python not too long ago, but unfortunatley I ran into some trouble with using a String Method.

This is my code:

 

famous_person = 'bruce lee'
message ='famous_person.title()' +  'once said,' + '"the more we value things, the less we value ourselves."'
print(message)



Error:
famous_person.title() once said, "the more we value things, the less we value ourselves."'
famous_person.title() doesn't change to the value I gave it. (bruce lee.) What am I doing wrong?

Greetings Indra
Quote
#2
Your string method is within the quotes making it apart of the string instead of a string method

This fixes your problem, however you shouldn't use concatenation. Its so unpythonic.
message ='{}'.format(famous_person.title()) +  'once said,' + '"the more we value things, the less we value ourselves."'
such as:
message ='{} once said, "the more we value things, the less we value ourselves."'.format(famous_person.title())
Quote
#3
If using 3.6 <= Python then you can consider f-strings as well:

>>> famous_person = 'bruce lee'                                            
>>> message = f'{famous_person.title()} once said, "the more we value things, the less we value ourselves."'                                      
>>> print(message)                                                         
Bruce Lee once said, "the more we value things, the less we value ourselves."
metulburr and ThomasL like this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Life of Brian: Conjugate the verb, "to go" !
Quote
#4
Thank you for all your solutions.
About the concatention, this was kind of the point. I was learning about concatention, but they did mention that it's not too Python-like.

Thanks for your help!
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  What is the use of call method and when to use it? everyday1 1 61 Jul-14-2019, 01:02 PM
Last Post: ichabod801
  Method not defined diskt 1 115 Jul-03-2019, 12:55 PM
Last Post: noisefloor
  web3 method rembrandt 3 155 Jun-04-2019, 05:43 PM
Last Post: buran
  [split] help with While method peterd1965 3 604 Jun-20-2018, 05:45 PM
Last Post: volcano63
  help with While method brawdhampshire 5 1,147 Jun-20-2018, 05:38 PM
Last Post: micseydel
  need method to look up dictionary key by value league55 3 569 Jan-17-2018, 10:58 PM
Last Post: metulburr
  Best Method for simple GUI? PythonAndArduino 4 1,056 Nov-17-2017, 06:22 AM
Last Post: heiner55

Forum Jump:


Users browsing this thread: 1 Guest(s)