Home arrow Python arrow 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).

  1. Python 3.1: Strings and Quotes
  2. Why Three Types of Quotes?
  3. Understanding Different Quotes
  4. Putting Two Strings Together
By: James Payne
Rating: starstarstarstarstar / 2
May 11, 2010

print this article



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:

Hello World!

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!

>>> More Python Articles          >>> More By James Payne

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- Tuples and Other Python Object Types
- The Dictionary Python Object Type
- String and List Python Object Types
- Introducing Python Object Types
- Mobile Programming using PyS60: Advanced UI ...
- Nested Functions in Python
- Python Parameters, Functions and Arguments
- Python Statements and Functions
- Statements and Iterators in Python

Developer Shed Affiliates


Dev Shed Tutorial Topics: