0% found this document useful (0 votes)
11 views5 pages

Python String Manipulation Guide

The document provides an overview of string manipulation in Python, explaining that strings are sequences of characters enclosed in quotes. It covers various operations such as determining string length, traversing strings, and using basic, membership, and comparison operators. Additionally, it introduces the ord() function for obtaining the Unicode value of a character.

Uploaded by

punit541985
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views5 pages

Python String Manipulation Guide

The document provides an overview of string manipulation in Python, explaining that strings are sequences of characters enclosed in quotes. It covers various operations such as determining string length, traversing strings, and using basic, membership, and comparison operators. Additionally, it introduces the ord() function for obtaining the Unicode value of a character.

Uploaded by

punit541985
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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.

*********************************************************************

You might also like