Skip to content
Parallax Learn

Parallax Learn

  • Welcome
  • Tutorials
        • Tutorial Series head tag

          Tutorial Series
        • Tutorial Series

          The special, classroom-ready series pages are organized collections of tutorials for our most popular hardware and/or languages. The tutorials for each topic are conveniently accessible from a single page, shown in the order it is recommended that they be completed.
        • Robotics Series Head tag

          Robotics Series
        • Robotics Series

          • Artificial Intelligence
          • Cybersecurity: Radio Data tutorialCybersecurity
          • cyber:bot + Python
          • cyber:bot + MakeCode
          • Boe-Bot Tutorial SeriesBoe-Bot
          • Arduino Shield-Bot
          • ActivityBot with C TutorialsActivityBot + C
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot + BlocklyProp
          • Scribbler 3 Tutorial SeriesScribbler 3
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education
          • Propeller C-Language BasicsPropeller C Basics
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit + C
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit + BlocklyProp
          • Badge WX Tutorial SeriesBadge WX
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics
          • View All Tutorial Series »
        • Browse Tutorials
        • Browse Tutorials

          Individual tutorials sorted by robot or kit, and language.
        • By Robot or Kit
          • ActivityBot
          • SumoBot WX
          • Boe-Bot
          • Shield-Bot
          • cyber:bot
          • Badge WX
          • ELEV-8
          • ARLO
        • By Language
        • By Language

          • Propeller C
          • Arduino
          • BlocklyProp
          • PBASIC
          • Python
          • MakeCode
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses
  • Strings & Characters Primer

Strings & Characters Primer

Try This: Display with Variable Labels

Let’s try modifying the script so that it displays s = ABC 123 instead of just ABC 123 in the terminal. That way, you’ll know that the terminal is displaying the contents of the s variable you created. This is very useful in a script that has many variables!

Example script: first_string_try_this

  • Change project’s name from  first_string_intro to first_string_try_this.
  • Change print(s) to print(“s = “, s).
  • Save the modified script.
  • Click the Send to micro:bit button.
# first_string_try_this

from microbit import *

sleep(1000)

s = "ABC 123"
print("s =", s)
  • Check the results in the serial monitor.
  • Verify that it displays s = ABC 123

Your Turn – More Elaborate Strings

This script has some of the fancier strings that were discussed earlier.  s1 is multiline, s2 is a single line that has been split across multiple lines in the Python editor.  S3 is a string in double-quotes that contains a couple of single quotes.  S4 has three escape characters, \t for tab, \’ for a single quote, and \n for the invisible character that advances the cursor to the next line.

Example script: first_string_your_turn

  • Enter, name, and save first_string_your_turn.  
  • Click the Send to micro:bit button.
# first_string_your_turn

from microbit import *

sleep(1000)

s1 = """s1 is a string
with more than one line
enclosed by three double-quotes."""

s2 = "s2 is a string with only one line "\
"that has been split into multiple "\
"lines to fit in your code editor. "\

s3 = "s3 is in double-quotes but 'contains' single-quotes."

s4 = 's4 has tab \t apostrophe \', and newline \n...for next line.'

print(s1)
print(s2)
print(s3)
print(s4)
  • Check the results in the serial monitor.
  • Verify that the:
    • s1 string displays as three lines.
    • s2 string displays as a single line, but might wrap inside the terminal.
    • s3 string contains two apostrophe single-quotes.
    • s4 string displays a tab, an apostrophe single-quote, and displays …for next line on the line below.

Keep in mind that some of the lines might wrap depending on the width of the browser and possibly due to settings inside the terminal.

 


Printer-friendly version
First String
Prev
Characters Inside Strings
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024

© 2025 Parallax Learn • Built with GeneratePress