2 The crow’s nest: Working with strings

 

Avast, you corny-faced gollumpus! Ye are barrelman for this watch. D’ye ken what I mean, ye addle-pated blunderbuss?! Ah, landlubber ye be! OK, then, you are the lookout in the crow’s nest--the little bucket attached to the top of a mast of a sailing ship. Your job is to keep a lookout for interesting or dangerous things, like a ship to plunder or an iceberg to avoid. When you see something like a narwhal, you are supposed to cry out, “Ahoy, Captain, a narwhal off the larboard bow!” If you see an octopus, you’ll shout “Ahoy, Captain, an octopus off the larboard bow!” (We’ll assume everything is “off the larboard bow” for this exercise. It’s a great place for things to be.)

From this point on, each chapter will present a coding challenge that you should complete on your own. I will discuss the key ideas you’ll need to solve the problems as well as how to use the provided tests to determine when your program is correct. You should have a copy of the Git repository locally (see the setup instructions in the book’s introduction), and you should write each program in that chapter’s directory. For example, this chapter’s program should be written in the 02_crowsnest directory, where the tests for the program live.

In this chapter, we’re going to start working with strings. By the end, you will be able to

2.1 Getting started

 
 

2.1.1 How to use the tests

 
 
 

2.1.2 Creating programs with new.py

 
 
 

2.1.3 Write, test, repeat

 

2.1.4 Defining your arguments

 
 

2.1.5 Concatenating strings

 
 
 

2.1.6 Variable types

 
 
 
 

2.1.7 Getting just part of a string

 
 

2.1.8 Finding help in the REPL

 
 
 
 

2.1.9 String methods

 
 

2.1.10 String comparisons

 
 
 

2.1.11 Conditional branching

 
 
 

2.1.12 String formatting

 
 
 
 

2.1.13 Time to write

 
 

2.2 Solution

 

2.3 Discussion

 
 
 
 

2.3.1 Defining the arguments with get_args()

 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage