Strings
A string is a sequence of characters.
We can enclose characters in quotes (single, double or triple).
This sequence of characters may include a letter, a number, a special
character or a backslash.
The triple quotes are typically used for strings that span multiple
lines.
Strings
Text enclosed in single quotes or double quotes
Examples:
A=“GIIS”
A=‘GIIS’
Empty string
A=“ ”
A=‘’
Traversing/ Iterating a string
Accessing all the elements of the string one after the other by using
the subscript or index value.
Traversing using for loop
Method 1: using range in for loop
Method 2: using sequence in for loop
Method 3: using while loop
Traversing using for loop
Examples in Python
Indexing
Positive indexing : starts from 0 to length-1(from left to right)
Negative indexing : starts from -1 to -length(from right to left)
Indexing
Examples in Python
String operators
Concatenation
Examples :
Replicating string
* operator
Examples:
Membership operator
For checking whether a particular string/character exits in the given
string or not
in operator
not in operator
Membership operator
Examples in Python
Comparison operators
>
<
>=
<=
==
!=
Comparison operators
Examples in Python
String slicing
String_name[start,stop,step]