[Tutor] variabel from raw input into re.search?

Tommy Kaas tommy.kaas at kaasogmulvad.dk
Fri Jan 7 14:18:13 CET 2011


You have 3 options, string concatenation, and two styles of formatting:

 

>>> name = 'Sir Arthur'

>>> '.*' + name + '.*'

'.*Sir Arthur.*'

>>> '.*%s.*' % (name, )

'.*Sir Arthur.*'

>>> '.*{0}.*'.format(name)

'.*Sir Arthur.*'

>>> '.*{name}.*'.format(name=name)

'.*Sir Arthur.*'

 

The last two examples are different ways to accomplish the same thing.

 

HTH,

Wayne

 

Thanks for the suggestion. Very useful.

Tommy

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110107/4f8c81e6/attachment.html>


More information about the Tutor mailing list