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

String Features: Indexing, Functions, Methods

Each character in a string has an index number. That index starts at the first character, counting from zero.

For example, in s = “Hello string”, H has an index of 0, e has an index of 1, l has an index of 2, and so on, up through g with an index of 11.  See how even the space between Hello and string is a character with an index?

Python has many tools for accessing, manipulating, and converting string information.  Here is one indexing example where the 6th character ’s’ is copied to the c variable and then printed. 

Python has built-in functions for certain string operations:

  • ord() — Returns the ASCII value of a character
  • chr() — Returns the character of an ASCII value
  • len() — Returns the length of a string
  • str() — Converts other types of objects to string

Additionally, strings that represent other data types can be converted to those types with built-in functions like int(), float(), dict(), list() and more.  Example:

s = "123"       # A string with numbers, but cannot be used in calculations
n = int(s)      # Convert to an int type
n = n + 1       # The result can be used in calculations

 

The string class has many methods.  Some return information about the string.  Others return new strings that are changed versions of the originals, and there are also some that return different types of objects that contain the string’s characters.  A few examples are shown below.

  • Given the example string shown, can you anticipate what each variable would look like printed?
string = "This is a string.  It is a sequence of characters!"

char_index = string.find("sequence")          # returns index of first letter in sequence
new_string = string.replace("It", "A string") # replaces "It" with "A string"
char_list = list(string)                      # converts a string into a list
lower_case = string.lower()                   # converts string to all lower case
upper_case = string.upper()                   # converts string to all upper case

 


Printer-friendly version
Strings for Exchanging Data
Prev
First String
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress