Strings

Overview

Python has built-in support for strings and all of the common string manipulation actions.

Concatenation

Strings can be concatenated with the + operator.

Repetition

Indexing

Slicing

The slicing of strings can be easily done by using array-like syntax on a string object.

Find The Length

To find the length of a Python string, use the len() function as shown below:

To get the amount of memory (in bytes) used to store a string, use the getsizeof() function from sys:

Note that the number of bytes assigned to store the string may be rather arbitrary and much larger than the number of characters in the string itself.

 

Posted: August 17th, 2017 at 4:09 am
Last Updated on: August 17th, 2017 at 4:24 am