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

Understanding Python Strings and Operations

A string is defined as a sequence of characters that can be enclosed in single, double, or triple quotes, with triple quotes used for multi-line strings. The document covers various operations on strings, including traversing, indexing, concatenation, replication, membership, and comparison operators, along with examples in Python. String slicing is also mentioned, using the format String_name[start, stop, step].
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views15 pages

Understanding Python Strings and Operations

A string is defined as a sequence of characters that can be enclosed in single, double, or triple quotes, with triple quotes used for multi-line strings. The document covers various operations on strings, including traversing, indexing, concatenation, replication, membership, and comparison operators, along with examples in Python. String slicing is also mentioned, using the format String_name[start, stop, step].
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

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]

You might also like