MY 5TH WEEK AT BLOCKFUSE_LABs.
Still on data types in python, this week i focused on gaining more ground knowledge on strings aka the most common text type. A string in the python context is used to store and represent a text.
A python string has four key features and they are:
***Text data:** this stores readable texts such as "welcome!","1,2,3".
***Unicode:** this supports characters from all languages,emojis and symbols.
***Immutable:** this means that after creation it cannot be changed, it can only be rewritten.
***Sequence:** in python a sequence is an ordered collection of items that can be indexed and sliced i.e characters are ordered, indexable and sliceable.
**INDEXING and SLICING**
Indexing - this is the manner or way with which you access individual elements in a sequence like string, list etc. Using square brackets '[]' and a number to access an item by its position (index) in a sequence. eg;
```python!
d = "programme"
print(d[0]) #output=p
```
Slicing - this is a core python feature that allows users to extract part of a sequence like string, list, tuples etc. eg;
```python!
d = "programme"
print(d[1:4) #output=rog
```
Further more ;
The **'len'** function: this is a built in function used to report the length (number of items) of an object like list, string, dict etc. eg;
```python!
#count characters in string
str = ("the badbest")
print(len(str)) #output=10
```
Thanks for following up!.