Wiley 978-0-7645-9654-4 Datasheet

Browse online or download Datasheet for Software manuals Wiley 978-0-7645-9654-4. Wiley Beginning Python User Manual

  • Download
  • Add to my manuals
  • Print
  • Page
    / 12
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 0
1
Programming Basics
and Strings
This chapter is a gentle introduction to the practice of programming in Python. Python is a very
rich language with many features, so it is important to learn to walk before you learn to run.
Chapters 1 through 3 provide a basic introduction to common programming ideas, explained in
easily digestible paragraphs with simple examples.
If you are already an experienced programmer interested in Python, you may want to read this
chapter quickly and take note of the examples, but until Chapter 3 you will be reading material
with which you’ve probably already gained some familiarity in another language.
If you are a novice programmer, by the end of this chapter you will have learned some guiding
principles for programming, as well as directions for your first interactions with a programming
language Python. The exercises at the end of the chapter provide hands-on experience with the
basic information that you’ll have learned.
How Programming Is Different
from Using a Computer
The first thing you need to understand about computers when you’re programming is that you
control the computer. Sometimes the computer doesn’t do what you expect, but even when it
doesn’t do what you want the first time, it should do the same thing the second and third time
until you take charge and change the program.
The trend in personal computers has been away from reliability and toward software being built
on top of other, unreliable, software. The results that you live with might have you believing that
computers are malicious and arbitrary beasts, existing to taunt you with unbearable amounts of
extra work and various harassments while you’re already trying to accomplish something. If you
do feel this way, you already know that you’re not alone. However, after you’ve learned how to
program, you gain an understanding of how this situation has come to pass, and perhaps you’ll
find that you can do better than some of the programmers whose software you’ve used.
04_596543 ch01.qxd 6/29/05 10:59 PM Page 1
COPYRIGHTED MATERIAL
Page view 0
1 2 3 4 5 6 ... 11 12

Summary of Contents

Page 1 - COPYRIGHTED MATERIAL

1Programming Basicsand StringsThis chapter is a gentle introduction to the practice of programming in Python. Python is a veryrich language with many

Page 2 - Programming Copes with Change

In the second string, the Q. is stranded in the middle, with John and Public far to either side. Thebehavior on its right-hand side has just been expl

Page 3 - The First Steps

codeEditor can run a Python shell, where you can experiment with simple Python programming lan-guage statements.Within the shell, you have learned the

Page 4 - Chapter 1

04_596543 ch01.qxd 6/29/05 10:59 PM Page 12

Page 5 - What Is a String?

Note that programming in a language like Python, an interpreted language, means that you are notgoing to need to know a whole lot about computer hardw

Page 6 - Why the Quotes?

being asked to exceed their capabilities, and they can fail gracefully by notifying their users that they’vestopped. In the best cases, you can create

Page 7

or where something happened, based on the line number in the file. This is one of the features of a goodprogramming editor, and it makes it much easie

Page 8 - Putting Two Strings Together

After you’ve started the shell, you’ll be presented with some information that you don’t have to be con-cerned about now (from, import, pcapp, and so

Page 9 - How It Works

Why the Quotes?Now, back to strings in particular. Strings are the basic unit of text in Python. Unlike some other pro-gramming languages, a single le

Page 10 - Displaying Strings with Print

significance from other special characters, such as quotes. This character in Python is the backslash ( \).Therefore, if you have to quote some text w

Page 11 - Exercises

As you can see here, Python enables you to do what you want in triple-quoted strings. However, it doesraise one more question: What’s that \n doing th

Page 12

Putting Strings Together in Different WaysAnother way to specify strings is to use a format specifier. It works by putting in a special sequence ofcha

Comments to this Manuals

No comments