Learning Outcomes:

Upon successful completion of this lesson, you will be able to:

Strings (about 31 mins)


Lesson 1 of 10: What is a String?

A string is a sequence of characters. A string literal uses one of the following:

A string is immutable.

Python Strings (about 3 mins)


String Data Type

The following statement assigns a variable s with a string literal 'matrix': s = 'matrix

String Data Type.png

The first character can be specified using the square bracket with an index value ‘0’. The statement print(s[0]) displays m on the screen.

An Index Error occurred if you indexed beyond the end of a string. The statement print(s[6]) will encounter a runtime error.