Python Forum
Method not regocnized - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Method not regocnized (/thread-19178.html)



Method not regocnized - Lass86 - Jun-16-2019

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


RE: Method not regocnized - metulburr - Jun-16-2019

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())



RE: Method not regocnized - perfringo - Jun-16-2019

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."



RE: Method not regocnized - Lass86 - Jun-19-2019

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!