Strings and Console Output
This course will introduce you to strings and console output in Python.
StartStrings & Console Output
Lesson 1 of 2
- 3There are some characters that cause problems. For example: ‘There’s a snake in my boot!’ This code breaks because Python thinks the apostrophe in ‘There’s’ ends the string. We can use the backs…
- 4Great work! Each character in a string is assigned a number. This number is called the index. Check out the diagram in the editor. c = “cats”[0] n = “Ryan”[3] 1. In the above example, we cr…
- 5Great work! Now that we know how to store strings, let’s see how we can change them using string methods. String methods let you perform specific tasks for strings. We’ll focus on four st…
- 9Let’s take a closer look at why you use len(string) and str(object), but dot notation (such as “String”.upper()) for the rest. lion = “roar” len(lion) lion.upper() Methods that use dot notation …
- 10The area where we’ve been writing our code is called the editor. The console (the window to the right of the editor) is where the results of your code is shown. print simply displays your…
- 11Great! Now that we’ve printed strings, let’s print variables
- 12You know about strings, and you know about arithmetic operators. Now let’s combine the two! print “Life “ + “of “ + “Brian” This will print out the phrase Life of Brian. The + operator between …
- 13Sometimes you need to combine a string with something that isn’t a string. In order to do that, you have to convert the non-string into a string. print “I have “ + str(2) + “ coconuts!” This wil…
- 14When you want to print a variable with a string, there is a better method than concatenating strings together. name = “Mike” print “Hello %s” % (name) The % operator after the string is used to …
- 15Remember, we used the % operator to replace the %s placeholders with the variables in parentheses. name = “Mike” print “Hello %s” % (name) You need the same number of %s terms in a string as the…
- 16Great job! You’ve learned a lot in this unit, including: Three ways to create strings ‘Alpha’ “Bravo” str(3) String methods len(“Charlie”) “Delta”.upper() “Echo”.lower() Printing a string pr…
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory