Strings

String is a sequence of symbols. All of the symbols can be accessed via their indexes starting from 0.

Indexes

Let's say we have the string "computer". It's structure is the following:

string-structure

So if we need to print the first letter (c) and the 3rd letter (m), we do:

Output:

Length

Length is the count of the symbols contained in a string.

It's accessed via the len function.

Example:

Output:

Via len we can access the last symbol of a string.

Example:

Output:

Access outside of bounds

Accessing string outside of it's bounds results in exception.

Let's look the following example:

The string has indexes from 0 to 4. Accessing index outside of that bound (in this case 5) causes exception.

Contains

We can check if string is contained in a string via the in operator.

Examples:

Output:

in can be used to check if single or multiple symbols are contained in string.

If a negative statment is necessary, then not in needs to be used.

Examples:

Output:

String iteration

All symbols of a string can be iterated via for loop.

Let's print all letters of a word that are not vowels:

Output:

In this case letter not in 'aeiou' means that letter is a symbol that's not a vowel letter.