Start learning free

LESSON 2 OF 410 · WELCOME TO PYTHON

Introduction to Strings in Python

Lesson

TL ; DR:

  • To create a string in Python, we put some text inside single quotes
    ('Hello world') or double quotes ("Hello world").


  • Be careful not to forget any quote! This code missing a " at the end:

    print("Welcome!)

    would throw a SyntaxError




Full lesson:

How boring would our life as humans be if we communicated only using numbers? Luckily we have letters, words and languages to express what we think!

We can also use letters and words in Python to express more meaningful messages like we do in real life.


Strings:

In programming, a string is any block of text e.g. any sequence of characters from your keyboard (letters, numbers, spaces, symbols, etc.).

To create a string in Python, we put some text inside single quotes ('Hello world') or double quotes ("Hello world").

For example, we can use strings inside the print() function for printing messages to the console:

print('My name is Andy')
print("Welcome to AlgoCademy!")

The output of this code is:

My name is Andy
Welcome to AlgoCademy!


As you can see, the quotes are not printed. That's because quotes are not part of the string. Their job is solely to let Python know when a string declaration starts and when it ends.


Assignment
Follow the Coding Tutorial and let's work with strings!


Hint
Look at the examples above if you get stuck.


STEP 1 OF 1
    Ctrl + Enter to check