HomePython Page 2 - Python 3.1: Strings and Quotes
Why Three Types of Quotes? - Python
In this second part of a three-part series that introduces you to Python, you'll learn about the importance of strings, how they work, and why Python uses three different kinds of quote marks. It is excerpted from the book Beginning Python: Using Python 2.6 and Python 3.1,, written by James Payne, Developer Shed Editor-in-Chief (Wrox, 2010; ISBN: 0470414634).
The reasoning behind having three types of quotes is fairly simple. Letís say that you want to use a contraction in your sentence, as I have just done. If you type a sentence such as ď I canít believe itís not butter Ē into the shell, nothing much happens, but when you actually try to get the program to use that string in any way, you will get an error message. To show you what I mean, the following section introduces you to the print() function.
Using the print() Function
A function in Python (and every other programming language) is a tool developers use to save time and make their programs more efficient. Instead of writing the same code over and over again, they store it in a function, and then call upon that function when they need it. Donít worry too much about functions at the moment; they are covered in greater detail later on. For now, it is enough to know what the term means and how it relates to programming.
The print() function is used whenever you want to print text to the screen. Try the following example in your Python shell:
> > > print(ďHello World!Ē)
When you press Enter, you should see the following:
You will want to note several things here. First, as you were entering in the print() function, a pop - up appeared, showing you the various options available to you within the function.
Second, the text once more appeared in blue on the next line, but this time without quotation marks around it. This is because unlike in the previous examples, Python actually did something with the data.
Congratulations, you just wrote your first program!