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

Strings Manipulation

Uploaded by

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

Strings Manipulation

Uploaded by

anilperfect
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

COMPUTER SCIENCE : STRING MANIPULATION

Strings manipulation
Strings: It is a collection of characters kept in single
quotes, double quotes or triple quotes. It is a immutable
data type.
Example: a= ‘python’ or a= “python” or a= ‘’’ python ‘’’
Indexing: it refers to assigning integers or numbers to
each character of the string to access them.
It is of 2 types:
1. forward indexing: it starts from left to right and
numbers assigned are from 0 to length -1.
Example:

2. backward indexing: it starts from right to left and


numbers are assigned from -1 to length (negative)
Example:
COMPUTER SCIENCE : STRING MANIPULATION

String operations:
1. Concatenation: it joins 2 or more strings together by
using the ‘ + ’ operator. But a number and string can not
be operated by + at the same time.
Example:

2. Repetition/Replication: it repeats/replicates a string a


given number of times by using the ‘*’operator. But it
can’t work on string*string.
Example:

3. Membership: it tells if a string is a part of other string


or not by using the ‘in’ or ‘not in’ operators and gives
output as true or false.
Example:
COMPUTER SCIENCE : STRING MANIPULATION

4. Slicing: it fetches out a specific part of the string with


the help of the index numbers or range given by user. It
works on both forward and backward indexing.
*The range given has the format of
[starting : ending : skipping] as [3:10:2]
By default the skipping value is 1.
Example:

5.Traversing: it refers to iterating through the elements of


a string (one character at a time) by using for loop.
Example:

Input:
output:
COMPUTER SCIENCE : STRING MANIPULATION
COMPUTER SCIENCE : STRING MANIPULATION

You might also like