-
Notifications
You must be signed in to change notification settings - Fork 2
HFP CH 2
(textual data)
39 Pages Long
Description:
Chapter 2 is all about strings. Strings, strings, and more strings. It covers the basis of Strings, sub-strings and how to use them in detail. This chapter also covers Libraries. The use of, the format of, as well as what a Library is. It also covered a few of the libraries with brief intros on methods and functions.
Note: Because this chapter introduced bugs and issues as part of the learning process. I decided to start submitting issue reports for those. This serves as more practice for me with GitHub as well as a good history of why I submitted code that was wrong to begin with.
The Code:
The code used in this chapter is based around a Company called "Starbuzz". This company sells coffee and needed a program that would display the price of coffee to them. In the beginning (Before strings where introduced). The code was ugly and could not be presented to anyone. By the end you have a program that simply sends the message "Buy!" to the CEO of Starbuzz when the price of coffee is bellow a certain price. Thanks to the time library and sleep() function. Starbuzz will also not get any more letters from The Department of Webland Security (Yes its from the book) do to an accident DDOS attack against the beans-r-us company.
Main Concepts Covered:
- Strings are sequences of individual characters.
- Individual string characters are referenced by index.
- Index values are offsets that start from zero.
- Methods provide variables with built-in functionality.
- Programming libraries provide a collection of related pr-built code and functions.
- As well as having value, data in variables also have a "data type".
- Number is a data type.
- String is a data type.
Python Tools Covered:
-
s[4]
- access the 5th character of the variable "s", which is a string. -
s[b:12]
- access a sub-string within the string "s" (up to, but not including). -
s.find()
- method for searching strings. -
s.upper()
- method for converting strings to UPPERCASE. -
float()
- converts strings to decimal point numbers known as "floats" -
+
- addition operator -
>
- greater than operator -
urllib.request
- library for talking to the web. -
time
- library for working with dates/time
ERATA:
The book uses the wrong url to pull from in the code from page 58. The book goes back to using:
http://beans-r-us.biz/prices.html
When it should be using
http://beans-r-us.biz/prices-loyalty.html
This is not detrimental. The code will still functionally work. But you will be pulling the price from the marked up value for regular customers instead of the dropped price for loyalty customers. This is bad for Starbuzz and you since the code could never complete with a closing print of Buy! since you never get the low price requested. Besides, even though this is fictional. You want to provide your best to the Company right? :-)