STRING In PYTHON ISKD
STRING MANIPULATION IN PYTHON
In Python, a string is a data type that's typically used to represent text. A string could be
any series of characters, including letters, numbers, spaces, etc.
In Python strings, characters are enclosed in quotes of any type-single quotation marks,
double quotation marks and triple quotation marks.
All of the following lines are strings being assigned to a variable:
RETURN A STRING'S LENGTH
You can use the len () function to return a string's length. To do this, simply pass the
string in as an argument to the function.
STRING In PYTHON ISKD
TRAVERSING A STRING
Traversing refers to iterating through the elements of a string, one character at a time.
STRING IN REVERSE ORDER
STRING In PYTHON ISKD
STRING OPERATORS
BASIC OPERATORS
STRING CONCATENATION OPERATOR +
“Hot”+”Spot” will result into ‘HotSpot ‘
‘100 ‘+ ‘999 ‘ will result into ‘100999 ‘
STRING REPLICATION OPERATOR *
To use a * operator with strings, you need two types of operands – a string and a number ie
number*string or string*number
STRING In PYTHON ISKD
MEMBERSHIP OPERATORS :
in : Returns True if a character or a substring exists in the given string ;False otherwise
not in : Returns True if a character or a substring does not exists in the given string; False
otherwise
STRING In PYTHON ISKD
COMPARISON OPERATORS :
Python’s standard comparison operators (all relational operators ie <,<=,>,>=,==,!=) apply to
strings also.
The comparisons using these operators are based on the standard character-by-character
comparison rules for Unicode.(Dictionary order)
DETERMINING ORDINAL/UNICODE VALUE OF A SINGLE CHARACTER:
Python offers a built-in function ord( )
that takes a single character as a input
and returns the corresponding ordinal
Unicode value.
*********************************************************************