Working with Strings

A string is a collection of characters, in a sequence. "My name is Mark." is a string with 16 characters in it. Spaces and periods are separate characters. Strings start with single quotes or double quotes. As you have seen before you can actually do some simple “arithmetic” with strings using + and * as shown below. You can also get the length of any collection (including strings) with the len function.

Activity: CodeLens 1 (String_Manip)


Remember that strings must start and end with the same character. That character can be " or ', but whatever you use as the starting character must match the ending character.

Run the code below to see what type of error you get if you use a different starting character than ending character in a string. Then try to fix the 2 errors in the code and run the code again. You should get the same results as in CodeLens 1 (String_Manip) above.

You have attempted of activities on this page