Home > Articles > Open Source > Python

  • Print
  • + Share This
This chapter is from the book

Using Strings in the Real World

In previous hours, we’ve gone over how Python might help the waiter in our imaginary restaurant. What about the chef? How can strings benefit her?

Most obviously, she can store the specials of the day in a script that can be run later by the waiter. That way, he can run it and see what the specials are without bothering her.

In the following script, the chef has saved a number of specials. She then prints them out in a formatted list of the specials of the day.

breakfast_special = "Texas Omelet"
breakfast_notes = "Contains brisket, horseradish cheddar"
lunch_special = "Greek patty melt"
lunch_notes = "Like the regular one, but with tzatziki sauce"
dinner_special = "Buffalo steak"
dinner_notes = "Top loin with hot sauce and blue cheese. NOT BUFFALO MEAT."

print "Today's specials"
print "*"*20
print "Breakfast: ",
print breakfast_special
print breakfast_notes
print
print "Lunch: ",
print lunch_special
print lunch_notes
print
print "Dinner: ",
print dinner_special
print dinner_notes

When the waiter runs it, the following is printed out:

Today's specials
********************
Breakfast: Texas Omelet
Contains brisket, horseradish cheddar
Lunch: Greek patty melt
Like the regular one, but with tzatziki sauce
Dinner: Buffalo steak
Top loin with hot sauce and blue cheese. NOT BUFFALO MEAT.

If the cook wants to change the specials later, she can edit the first few lines in the file.

  • + Share This
  • 🔖 Save To Your Account