Strings using python -
Other than numbers python can also handle strings which can be expressed by several ways. In programming a string is a contiguous sequence of symbols or values such as a character string or digit string. Strings is declared in a '....' (single quotes) or "...." (double quotes).
By using '\n' you can insert the string to the new line by using print() command. For example:
We can concatenate string by using + operator. Concatenate means we can merge two or more separate strings by using + operator. For example:
Here 3*'py' means the string 'py' repeats 3 times and same for the 'thon' string.
Now we another method to concatenate two or more strings. In this method you have write strings next to each other without any operator. For example:
In the python string is stored in indexes. The index is start from 0 (zero). In python indexes also be calculated from reverse side and this index is start from -1. Lets see example
str = 'Python'
Indexes
0 | 1 | 2 | 3 | 4 | 5 |
P | y | t | h | o | n |
-6 | -5 | -4 | -3 | -2 | -1 |
Comments
Post a Comment