CLASS -11 COMPUTER SCIENCE
CHAPTER-5 STRING MANIPULATION
🔔To download textbook pdf click on the ''DOWNLOAD'' button below -
NOTES FOR COMPLETE UNDERSTANDING -
- Characters enclosed in
single , double or triple quotes (‘ ‘
,
“ “
,
‘’’
‘’’) is called a string.
- strings are immutable i.e. they can’t be updated.
- In a String , every character stays at a distinct position or index number that goes from 0 to s-1 (s is
the total number of characters in string).
- String can be created in following ways : 1. By providing values directly to a variable 2. By taking Input from user
- Traversal of string :
- Procedure to split each and every character of a string for some purpose is
called string traversal.
- 2 operators which can be applied upon
strings + and * are : » + (it is used to join two strings) • Like - “sea” + “shore” will result into “seashore” •Like- “7” + “2” will result into “42” •Like – “193” + “aqr” will result into “123pqr” »* (it is used to replicate the string) • like - 5*”#” will result into “#####” • Like - “go!” * 6 will result “go!go!go!go!go!go!”
- Membership Operators in Strings :
- 2 membership operators that works with strings are in and not in.
To understand the working of these operators, focus on the
given examples - • in operator results into True or False. eg. – “n” in “Sanjeevani” will result into True. – “ap” in “Sanjeevani” will result into False. – “anj” in “Sanjeevani” will result into True. • not in operator also results into True or False. eg. – “k” not in “Sanjeevani” will result into True. – “ap” not in “Sanjeevani” will result into True. – “anj” not in “Sanjeevani” will result into False.
- String Comparison Operators :
- Examples - • “p” == “p” True • “adc”==“adc” True • “a”!=“akc” True • “K”==“k” False • “abc” ==“Abc” False • ‘a’<‘A’ False (because Unicode value of lower case is higher than upper case)
- Accessing Ordinal/Unicode Values :
- Examples- >>>ord (‘A’) 65 >>>char(97) a >>>ord(‘a’) 97 >>>char(65) A
- String Slicing :
- word = “RESPONSIBILITY”
- word[ 0 : 13 ] will result into‘RESPONSIBILIT’
- word[ 0 : 4] will result into‘RESP’
- word[ 2 : 7 ] will result into‘SPONS’
- word[ -7 : -3 ] will result into ‘IBIL’
- word[ : 14 ] will result into‘RESPONSIBILITY’
- word[ : 6 ] will result into ‘RESPON’
- word[ 4 : ] will result into ‘ONSIBILITY’
- String Functions :
- String.capitalize() Converts first character to Capital Letter
- String.find() Outputs the Lowest Index of required Substring
- String.index() Outputs Index of Substring
- String.isalnum() Checks Alphanumeric Character
- String.isalpha() Checks if All Characters are Alphabets
- String.isdigit() Checks Digit Characters
- String.islower() Checks if all Alphabets in a String are Lowercase
- String.isupper() Outputs if all characters are uppercase characters
- String.join() Outputs a Concatenated String
- String.lower() Outputs lowercased string
- String.upper() Outputs uppercased string
- len() Outputs Length of an Object
- ord() Outputs Unicode code point for Unicode character
- reversed() Outputs reversed iterator of a sequence
- slice() creates a slice object specified by range()
🔔MORE MATERIALS TO BE UPLOADED STAY TUNED🔔