📖 generic · 12th TN - English Medium · COMPUTER SCIENCE · Page 120definition

STRINGS AND STRING MANIPULATION

Chapter 3: 4 · COMPUTER SCIENCE

STRINGS AND STRING MANIPULATION 12th Computer Chapter - - Strings and String Manipulation #A string defined within single quotes >>> print (‘Greater Chennai Corporation’) Greater Chennai Corporation #single quoted string defined within single quotes >>> print ('Greater Chennai Corporation's student') SyntaxError: invalid syntax #A string defined within double quotes >>>print (“Computer Science”) Computer Science #double quoted string defined within double quotes >>> print (''' "Computer Science" ''') "Computer Science" #single and double quoted multiline string defined within triple quotes >>> print (''' "Strings are immutable in 'Python', which means you can't make any changes once you declared" ''') "Strings are immutable in 'Python', which means you can't make any changes once you declared" Example Accessing characters in a String . Once you define a string, python allocate an index value for its each character. These index values are otherwise called as subscript which are used to access and manipulate the strings. The subscript can be positive or negative integer numbers.

The positive subscript is assigned to the first character and n- to the last character, where n is the number of characters in the string. The negative index assigned from the last character to the first character in reverse order begins with - . Example String S C H O O L Positive subscript Negative subscript - - - - - - 12th Computer Chapter - - str1 = input ("Enter a string: ") index= for i in str1: print ("Subscript[",index,"] : ", i) index + = Output Enter a string: welcome Subscript [ ] : w Subscript [ ] : e Subscript [ ] : l Subscript [ ] : c Subscript [ ] : o Subscript [ ] : m Subscript [ ] : e Example : Program to access each character with its positive subscript of a giving string str1 = input ("Enter a string: ") index=- while index >= -(len(str1)): print ("Subscript[",index,"] : " + str1[index]) index += - Output Enter a

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →