16.2. 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 16.2.1 (String_Manip)

Before you keep reading...

Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.

Note

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.

Do ‘simple arithmetic’ with the variables provided below to print ‘jellybeanjellybeanjellybean’.

Show Comments

Note

Discuss topics in this section with classmates.

Show Comments
You have attempted 1 of 8 activities on this page