Python Programming: Reema Thareja
Python Programming: Reema Thareja
Python Programming
Using Problem Solving Approach
Reema Thareja
Indexing: Individual characters in a string are accessed using the subscript ([ ]) operator. The expression in brackets
is called an index. The index specifies a member of an ordered set and in this case it specifies the character we want to
access from the given set of characters in the string.
The index of the first character is 0 and that of the last character is n-1 where n is the number of characters in the
string. If you try to exceed the bounds (below 0 or above n-1), then an error is raised.
3
Example:
Example:
10
Examples:
11
Examples:
12
13
14
Examples:
15
16
Examples:
17
19
Example:
20
21
Examples:
22
24
25
Examples:
26
Example:
The content of groups in a match can be accessed by using the group() function. For example,
• group(0) or group() returns the whole match.
• group(n), where n is greater than 0, returns the nth group from the left. 27
• group() returns all groups up from 1. © OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS RESERVED.