Tamilnadu Samacheer Kalvi 12th Computer Science Notes Chapter 8 Strings and String Manipulations Notes
String:
- String is a data type in python, which is used to handle array of characters.
- String is a sequence of Unicode characters that may be a combination of letters, numbers, or special symbols enclosed within single, double or even triple quotes.
Slicing:
- Slice is a substring of a main string.
- A substring can be taken from the original string by using [ ] operator and index or subscript values.
- Thus, [ ] is also known as slicing operator.
- Using slice operator, we have to slice one or more substrings from a main string.
General format of slice operation: str[start:end]
- Start is the beginning index and end is the last index value of a character in the string.
- Python takes the end value less than one from the actual index specified.
Stride:
- Slice is a substring of a main string.
- Stride is a third argument in slicing operation which refers to the number of characters to move forward after the first character is retrieved from the string.
Function: center ()
center () returns a string with the original string centered to a total of width columns and filled with fillchar in columns that do not have characters.
Function: find ()
- The find () is used to search the first occurrence of the substring in the given string.
- It returns the index at which the substring starts.
- It returns -1 if the substring does not occur the string.
Function: lower ()
lower () returns the exact copy of the string with all the letters in lowercase
Function: islower()
islower () returns True if the string is in lowercase.
Function: upper()
upper () returns the exact copy of the string with all letters in uppercase
Function: isupper()
isupperQ returns True if the string is in uppercase.
Function: title()
title() returns a string in title case.
Function: capitalize ()
capitalize () is used to capitalize the first character of the string.
Function: swapcase ()
swapcase () will change case of every character to its opposite case vice-versa.
Function: format()
- The format( ) is used with strings is very versatile and powerful function used for formatting strings.
- The curly braces {}are used as placeholders or replacement fields which get replaced along with format() function.
Function: count()
- count( ) returns the number of substrings occurs within the given range.
- Substring may be a single character.
Function: isalnum ()
- isalnum () returns True if the string contains only letters and digit. It returns False.
- If the string contains any special character like _,@,#,*,etc.
Function: isalpha()
isalpha() returns True if the string contains only letters Otherwise return False.
Function: isdigit ()
isdigit () returns True if the string contains only numbers. Otherwise it returns False