String: Python - 12th CBSE

String:
Strings Operations:
In python, consecutive sequence of characters is known as a string. An individual character in a string is
accessed using a subscript (index). The subscript should always be an integer (positive or negative) and
starts from 0. A literal/constant value to a string can be assigned using a single quotes, double quotes or
triple quotes. Strings are immutable i.e. the contents of the string cannot be changed after it is created.
+ (Concatenation)
* (Repetition )
in (Membership)
not in
range (start, stop[,step])
slice[n:m]
Example: Write the output from the following code:
1. A = 'Global'
B = 'warming'
print A+B
Ans: Globalwarming
2. A = 'Global'
Print 3*A
Ans: 'GlobalGlobalGlobal'
3. A='Global'
 'o' in A
Ans: True
4. A='Global'
 'g' in A
Ans: False
5. A='Global'
 'o' not in A
Ans: False
6. A='Global'
'g' not in A

Ans: True

No comments:

Post a Comment