0% found this document useful (0 votes)
4 views6 pages

Python Basic

This document provides a comprehensive overview of basic Python string operations, including methods for changing case (upper, lower, capitalize, title, swapcase), splitting and joining strings, stripping characters, and searching within strings (index, find, count). It also covers boolean checks for string properties, such as isupper, islower, isdigit, isalpha, and more. The document serves as a practical reference for performing various string manipulations in Python.

Uploaded by

k3bros242529
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Python Basic

This document provides a comprehensive overview of basic Python string operations, including methods for changing case (upper, lower, capitalize, title, swapcase), splitting and joining strings, stripping characters, and searching within strings (index, find, count). It also covers boolean checks for string properties, such as isupper, islower, isdigit, isalpha, and more. The document serves as a practical reference for performing various string manipulations in Python.

Uploaded by

k3bros242529
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

PYTHON BASIC

#UPPER
>>>s='kumaravel'
>>>s.upper()
'KUMARAVEL'

>>>s1='kumar123kumar'
>>>s1.upper()
'KUMAR123KUMAR'

#LOWER CASE
>>>s='KUMARAvel'
>>>s.lower()
'kumaravel'

>>>s1='123@KUMaravel'
>>>s1.lower()
'123@kumaravel'

# CAPITALIZE CASE
>>>s='kumar'
>>>s.capitalize()
'Kumar'

>>> s1='@kumar'
>>> s1.capitalize()
'@kumar'

>>> s2='12kumar'
>>> s2.capitalize()
'12kumar'

#TITLE CASE
>>> s='hello good morning'
>>> s.title()
'Hello Good Morning'

>>> s1='12hi bye'


>>> s1.title()
'12Hi Bye'

#SWAP CASE
>>> s1='Kumaravel kUTTY'
>>> s1.swapcase()
'kUMARAVEL Kutty'

#SPLIT
>>>s='happy morning'
>>>s.split()
['happy', 'morning']

>>>s='hi good morning have a nice day'


>>>s.split()
['hi', 'good', 'morning', 'have', 'a', 'nice', 'day']

#RSPLIT
>>>s='happy evening'
>>>s.rsplit()
['happy', 'evening']

>>>s='tata good night'


>>>s.rsplit()
['tata', 'good', 'night']

#JOIN
>>>'s'.join("kumaravel")
'ksusmsasrsasvsesl'

>>>'#'.join("kumar")
'k#u#m#a#r'

>>>'&'.join("kumar")
'k&u&m&a&r'

#STRIP
>>>s='kumaravel'
>>>s.strip('k')
'umaravel'

>>>s='morning'
>>>s.strip('ing')
'mor'

#L STRI
>>>s='kumaravel'
>>>s.lstrip('kumara')
'vel'

>>>s='123123442142112'
>>>s.lstrip('123')
'442142112'

>>>s='12312KUMARAVEL123'
>>>s.lstrip('123')
'KUMARAVEL123'

#R STRIP
>>>s='KUMARAVEL123'
>>>s.rstrip('123')
'KUMARAVEL'
>>>s='kumaravel'
>>>s.rstrip('avel')
'kumar'

>>>s='muthukumar'
>>>s.rstrip('kumar')
'muth'

#INDEX
>>> s1='happy morning'
>>> s1.index('m')
6

>>> s1.index('n')
9

>>> s1.index(s1[4])
4

#RINDEX
>>> s1='good evening'
>>> s1.rindex('n')
10

>>> s1.rindex('e')
7

#FIND
>>> s1='kumaravel'
>>> s1.find('a')
3

>>> s1.find('n',4,5)
-1

#RFIND
>>> s='kumaravel'
>>> s.rfind('a')
5

>>>s.rfind('v')
6

#COUNT
>>>s='muthu kumar'
>>>s.count('u')
3

>>>s.count('m')
2

>>>s.count('r')
1
#REPLACE
>>>s='good evening'
>>>s.replace('eve','mor')
'good morning'

>>>s.replace('good', 'bad')
'bad evening'

>>>s.replace('good','happy')
'happy evening'

#BOOLEAN
#ISUPPER
>>>s='KUMAR'
>>>s.isupper()
True

>>>s='kumar'
>>>s.isupper()
False

>>>s='KUmar'
>>>s.isupper()
False

#ISLOWER
>>>s='kumar'
>>>s.islower()
True
>>>s='Kumar'
>>>s.islower()
False
#ISDIGIT
>>>s='1234'
>>>s.isdigit()
True

>>>s='@123'
>>>s.isdigit()
False

>>>s='123kumar'
>>>s.isdigit()
False

#IS ALPHA
>>>s='KUMAR'
>>>s.isalpha()
True

>>>s='@kumar'
>>>s.isalpha()
False

>>>s='123'
>>>s.isalpha()
False

#IS ALNUM
>>>s='12KUMAR'
>>>s.isalnum()
True

>>>s='@123KUMAR'
>>>s.isalnum()
False

#IS IDENTIFIER
>>>s='5'
>>>s.isidentifier()
False

>>>s='hello'
>>>s.isidentifier()
True

>>>s='@kumar'
>>>s.isidentifier()
False

#IS SPACE
>>>s=''
>>>s.isspace()
False

>>>s=' '
>>>s.isspace()
True

>>>s='1'
>>>s.isspace()
False

#STARTS WITH
s='kumar'
s.startswith('k')
True

s.startswith('u',1)
True

s.startswith('o')
False

#ENDS WITH
s='kumaravel'
s.endswith('l')
True

s.endswith('r',0,5)
True

s.endswith('v',4,8)
True

You might also like