Before you keep reading...
Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.
Before you keep reading...
Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.
Chapter 4 - Summary¶
Chapter 4 included the following concepts from computing.
Append - You can add two strings together using the
+symbol. This is also called concatenate.
Capitalize - The capitalize function returns a new string with the first character capitalized.
Concatenate - You can use
+to concatenate (append) two strings like this
string3 = string1 + string2. This will create a new string called
string3with all the characters from the first string,
string1, followed by all the characters in the second string,
Function - A function returns a value. Function can take input as well, but don’t have to. An example is the string
lower()function that returns a string with all lowercase letters.
Immutable - Immutable means that it does not change. Strings are immutable in Python. When you call a function that appears to change a string, it will actually return a new string.
Index - An index is a number associated with the position of a character in a string. In Python the first character in a string is at index 0.
Object - An object can have behavior (things it can do). For example a turtle object can go forward a specified amount. Strings and turtles are objects in Python.
String - A string is a sequence of characters. You specify a string as characters inside a pair of single, double, or triple quotes.
Substring - A substring is a part of a string. One substring of “Hi there” would be “Hi”.
Summary of String Functions¶
Chapter 4 also included the following string functions.
append - You can add two strings together using the
+symbol. This is also called concatenate. The result of
"Happy" + " Birthday"is
find - The find function takes a string as input and returns the index of the first occurence of that string in the string the function is called on. The code
len - The len function that can take a string as input and returns the number of characters in the string including any spaces. For example
len("Hi there")will return 8.
lower - The lower string function returns a new string with only lowercase letters. For example
slice - You can get part of a string which is also called a substring using [start] or [start:end] which will return a substring of the current string starting at the given start position and if an end position is given ending at the character before the end position. For example
This is the end of chapter 4. We would love it if you could give us some feedback on this chapter at https://www.surveymonkey.com/r/ch4-teacher-fb. You might want to open this link in a new tab to make it easier for you to return to your place in this ebook.