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!'

Single-Quoted Strings and Escaping Quotes :

Strings are values, just as numbers are:

>>> "Hello, world!"

'Hello, world!'

There is one thing that may be a bit surprising about this example, though:

When Python printed out our string, it used single quotes, whereas we used double quotes.

What’s the difference? Actually, there is no difference:

>>> 'Hello, world!'

'Hello, world!'

Here, we use single quotes, and the result is the same. So why allow both?

Because in some cases it may be useful:

>>> "Let's go!"

"Let's go!"

>>> '"Hello, world!" she said'

'"Hello, world!" she said'

Python Strings :

The raw_input and "Hello, " + name + "!"

Let’s go for the "Hello" part first and leave raw_input for later.

The first program in this chapter was simply print "Hello, world!"

But what is "Hello, world!"? It’s called a string (as in “a string of characters”).

Strings are found in almost every useful, real-world Python program and have many uses.

Their main use is to represent bits of text, such as the exclamation “Hello, world!”

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