Monday, May 25, 2009

Concatenating Strings : 

>> "Let's say " '"Hello, world!"'

Simply written two strings, one after the other, and Python automatically concate-nates them (makes them into one string).

This mechanism isn’t used very often, but it can be useful at times.

However, it works only when you actually write both strings at the same time, directly following one another:

>>> x = "Hello, "

>>> y = "world!"

>>> x y

SyntaxError: invalid syntax

It is just a special way of writing strings, not a general method of concat-enating them.

How, then, do you concatenate strings? Just like you add numbers:

>>> "Hello, " + "world!"

'Hello, world!'

>>> x = "Hello, "

>>> y = "world!"

>>> x + y

'Hello, world!'

No comments:

Data Science - 103 (Kapil Sharma)

Cloud Computing Basic:-  In this the PC is on service provider data center and secuirty maintenance and upgrades are done by the service pro...