Class 11 String Manipulation Notes covering Indexing, String Functions, Traversing String, Slicing String, String Concatenation, String Repetition, Membership etc. Strings in Python Class 11 is prepared very concisely for students of class 11 computer science to get highest marks effortlessly.
Contents
What is Strings?
- String is basically a sequence which is made up of one or more UNICODE characters.
- Character in string can be any letter, digit, whitespace or any other symbol.
- String can be created by enclosing one or more characters in single, double or triple quotes.
Examples:
![](https://i0.wp.com/techtipnow.in/wp-content/uploads/2022/10/string-in-python.png?resize=623%2C248&ssl=1)
INDEXING – Accessing characters in a string
- Individual character in a string can be accessed using indexes.
- Indexes are unique numbers assigned to each character in a string to identify them
- Index always begins from 0 and written in square brackets “[]”.
- Index must be an zero, positive or negative integer.
- We get IndexError when we give index value out of the range.
Examples:
![](https://i0.wp.com/techtipnow.in/wp-content/uploads/2022/10/accessing-character-in-string.png?resize=636%2C245&ssl=1)
Negative Indexing
- Python allows negative indexing also.
- Negative indices are used when you want to access string in reverse order.
- Starting from the right side, the first character has the index as -1 and the last character (leftmost) has the index –n where n is length of string.
![](https://i0.wp.com/techtipnow.in/wp-content/uploads/2022/10/negative-index-string-python.png?resize=538%2C91&ssl=1)
Is string immutable?
- Yes, string is immutable data type. The content of string once assigned cannot be altered than.
- Trying to alter string content may lead an error.
![](https://i0.wp.com/techtipnow.in/wp-content/uploads/2022/10/string-is-immutable.png?resize=646%2C151&ssl=1)
String operations
String supports following operations:
- Concatenation
- Repetition
- Membership
- Slicing
Concatenation
- Concatenation refers to joining two strings.
- Plus (‘+’) is used as concatenation operator.
![](https://i0.wp.com/techtipnow.in/wp-content/uploads/2022/10/string-concatenation.png?resize=628%2C123&ssl=1)
Repetition
- Repetition as it name implies repeat the given string.
- Asterisk (‘*’) is used as repetition operator.
![](https://i0.wp.com/techtipnow.in/wp-content/uploads/2022/10/string-repetition.png?resize=482%2C84&ssl=1)
Membership
- Membership operation refers to checking a string or character is part or subpart of an existing string or not.
- Python uses ‘in’ and ‘not in’ as membership operator.
- ‘in’ returns true if the first string or character appears as substring in the second string.
- ‘not in’ returns true if the first string or character does not appears as substring in the second string.
![](https://i0.wp.com/techtipnow.in/wp-content/uploads/2022/10/membership-operator-python.png?resize=631%2C120&ssl=1)
Slicing
- Extracting a specific part of string or substring is called slicing
- Subset occurred after slicing contains contiguous elements
- Slicing is done using index range like string[start_index : end_index : step_value]
- End index is always excluded in resultant substring.
- Negative index can also be used for slicing.
![](https://i0.wp.com/techtipnow.in/wp-content/uploads/2022/10/slicing-string.png?resize=640%2C489&ssl=1)
Traversing a String
- Traversing a string refers to accessing each character of a given string sequentially.
- For or while loop is used for traversing a string
![](https://i0.wp.com/techtipnow.in/wp-content/uploads/2022/10/traversing-string-for-loop.png?resize=644%2C363&ssl=1)
![](https://i0.wp.com/techtipnow.in/wp-content/uploads/2022/10/traversing-string-while-loop.png?resize=643%2C395&ssl=1)
String Functions
![](https://i0.wp.com/techtipnow.in/wp-content/uploads/2022/10/string-function-1.png?resize=649%2C821&ssl=1)
![](https://i0.wp.com/techtipnow.in/wp-content/uploads/2022/10/string-functions.png?resize=649%2C955&ssl=1)
Very helpful