Chevron Left Icon
Strings & Console Output
Lesson 1 of 2
Chevron Right Icon
  1. 1

    Another useful data type is the string. A string can contain letters, numbers, and symbols. […] 1. In the above example, we create a variable […] and set it to the string value […

  2. 2

    Excellent! Let’s get a little practice in with strings.

  3. 3

    There are some characters that cause problems. For example: […] This code breaks because Python thinks the apostrophe in […] ends the string. We can use the backslash to fix the problem, …

  4. 4

    Great work! Each character in a string is assigned a number. This number is called the index. Check out the diagram in the editor. […] 1. In the above example, we create a new variable c…

  5. 5

    Great 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…

  6. 6

    Well done! You can use the […] method to get rid of all the capitalization in your strings. You call […] like so: […] which will return […] .

  7. 7

    Now your string is 100% lower case! A similar method exists to make a string completely upper case.

  8. 8

    Now let’s look at […] , which is a little less straightforward. The […] method turns non-strings into strings! For example: […] would turn […] into […] .

  9. 9

    Let’s take a closer look at why you use […] and […] , but dot notation (such as […] ) for the rest. […] Methods that use dot notation only work with strings. On the other hand, [….

  10. 10

    The 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. […] simply displays yo…

  11. 11

    Great! Now that we’ve printed strings, let’s print variables

  12. 12

    You know about strings, and you know about arithmetic operators. Now let’s combine the two! […] This will print out the phrase […] . The […] operator between strings will ‘add’ them t…

  13. 13

    Sometimes 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. […] This will print […] . The […] met…

  14. 14

    When you want to print a variable with a string, there is a better method than concatenating strings together. […] The […] operator after the string is used to combine a string with varia…

  15. 15

    Remember, we used the […] operator to replace the […] placeholders with the variables in parentheses. […] You need the same number of […] terms in a string as the number of variab…

  16. 16

    Great job! You’ve learned a lot in this unit, including: Three ways to create strings […] String methods […] Printing a string […] Advanced printing techniques […]

  1. 1

    A lot of times you want to keep track of when something happened. We can do so in Python using […] . Here we’ll use […] to print the date and time in a nice format.

  2. 2

    We can use a function called […] to retrieve the current date and time. […] The first line imports the […] library so that we can use it. The second line will print out the current d…

  3. 3

    Notice how the output looks like […] . What if you don’t want the entire date and time? […] You already have the first two lines. In the third line, we take the year (and only the year) …

  4. 4

    What if we want to print today’s date in the following format? […] . Let’s use string substitution again! […] Remember that the standalone […] operator after the string will fill the …

  5. 5

    Nice work! Let’s do the same for the hour, minute, and second. […] In the above example, we just printed the current hour, then the current minute, then the current second. We can again use …

  6. 6

    We’ve managed to print the date and time separately in a very pretty fashion. Let’s combine the two! […] The example above will print out the date, then on a separate line it will print the t…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo