The len() Function

The Len Function

This function is extremely useful and often comes up in coursework tasks.

It is used to work out how many characters have been used in a string or another type of object.

Look and run the code below to see a simple example.

 

TASK

Try this for yourself by editing the script below. Create a variable that contains a string and work out the length of the string

The len function can also be used in loops when iterating.

 

Another example

For example if you wanted to print out how many character there were in a string and which character it was…

Posted in CS and tagged , , , , .

Leave a Reply

Your email address will not be published. Required fields are marked *

*