LPTHW - Day 13 Strings and Text

No Day 12 , I fall asleep on my lappy while going half-way through exercise 6 in LPTHW .

Multi-variables formatted string in Python 2.x
>>> print "No %s, No %s" % ('Pain', 'Gain')
No Pain, No Gain

In  Python3, using positional (ordinal) arguments
>>> print ("No {0}, No {1}".format('Pain', 'Gain'))
No Pain, No Gain

or named arguments, which I loves alot since it make the code readable at a glance.
>>>print ("No {first}, No {second}".format(first='Pain', second='Gain'))
No Pain, No Gain

While in PHP
php> printf("No %s No %s", 'Pain', 'Gain');
No Pain No Gain

String Concatenation in Python
>>> print "foo"+"bar"
foobar

In Python 3
>>> print ("foo"+"bar")
foobar

Meanwhile in PHP
print "foo" . "bar";

No comments:

Post a Comment