String in Python.|access string | len() function| Traversal of String.
String:
String is a sequence , String is the one of the popular data type in the python, use and manipulatation of string in python is very easy. String is collection of characters , we can create them simply by "" or ''. Python '' same as "". It is as simple as assigning the value to the varible.
Example:
Access string:
In python string are store as an individual characters in continueous memory location. The benefit of using string is, it can be access from both the direction i.e forward as well as backward.
Both forward and backward indexing are provided by using string in python.
Forward indexing starts from 0,1,2,3,....,n.
Backward indexing starts from -1,-2,....,-n.
Traversal With Loop:
If we consider a string is as group of characters then processing those character. one by one involves lot of calculation . Generally we have to strart at begining select each character in term and continue till end this pattern of processing is called Traversal.
In Python we traverse a string either using for loop or while loop.
Example:
Traversal of string using for loop:String Slicing:
Abstracting the subset of a string is called String Slicing. If you take subset of string from original string by using index operator ([]) in python which also known as Slicing opertaor.
This will return part of string starting from undex start to index n.
Comments
Post a Comment