Strings in Python
- Any sequence of characters within either single quotes to triple quotes is considered as a string.
- By using single quotes we can create string class of one lines.
- By using triple quotes we can create one or more line of string.
- String is a immutable object.
- String support +ve and -ve index.
- +ve index start to zero(0) and -ve index start form (-1).
'rahul' -Single quotes
"rahul" -Single quotes
'''rahul''' -Triple quotes
Ex1:-
x='rahul'
print(type(x))Output:-
<class 'str'>
Method of String:
1. Capitalize:-First capital letter of a paragraph.
2. Title:-First letter of any word.
3. Lower:-All paragraph lower case.
4. Upper:-All paragraph upper case.
5. Split:- Gives value splites on list format.
Ex2:-
x="rahul"
print(x.capitalize())
print(x.title())
print(x.upper())
print(x.lower())
print(x.split())
Output:-
Rahul
Rahul
RAHUL
rahul
['rahul']
Post a Comment
0 Comments