0% found this document useful (0 votes)
211 views

PYthon Class 16 Telugu

The document discusses various string methods in Python like title(), capitalize(), swapcase(), isalnum(), isalpha(), isdigit(), islower(), isnumeric(), isspace(), istitle(), isupper(), center(), ljust(), rjust(), and zfill(). These methods are used to check, format, and manipulate strings. They return True/False or a new formatted string depending on whether certain string conditions are met or the string is padded/justified according to the method syntax.

Uploaded by

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

PYthon Class 16 Telugu

The document discusses various string methods in Python like title(), capitalize(), swapcase(), isalnum(), isalpha(), isdigit(), islower(), isnumeric(), isspace(), istitle(), isupper(), center(), ljust(), rjust(), and zfill(). These methods are used to check, format, and manipulate strings. They return True/False or a new formatted string depending on whether certain string conditions are met or the string is padded/justified according to the method syntax.

Uploaded by

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

Python Class 16

=====================

title()
~~~~~~~~~

It is used to return or display the given string in title case

Syntax:
----------

str.title()

eg:

>>> str="python programming"


>>> x=str.title()
>>> print(x)
Python Programming
>>>

capitalize()
-------------------

It is used to display or return the given string of first character should be


in capital letter

syntax:
~~~~~~~~~~

str.capitalize()

eg:

>>> str="welcome to the world of programming"


>>> x=str.capitalize()
>>> print(x)
Welcome to the world of programming
>>>

swapcase()
==============

It is used to display or return the given string in to reverse format(lower


case become upper case and vice versa)

Syntax:
~~~~~~~~~~~~

str.swapcase()

eg:

>>> str="abcdEFGHijklMNOPqrstUVWXyz"
>>> x=str.swapcase()
>>> print(x)
ABCDefghIJKLmnopQRSTuvwxYZ
>>>
Checking Type of string(s) Functions
========================================

isalnum()
~~~~~~~~~~

It is used to return or display True when the given string contains the
alphabets and numbers otherwise False will return

The special character is not allowed

Syntax:
~~~~~~~~~

str.isalnum()

eg:

>>> str="python3"
>>> x=str.isalnum()
>>> print(x)
True
>>>
>>>
>>> str="python 3"
>>> x=str.isalnum()
>>> print(x)
False
>>>

isalpha()
~~~~~~~~~~~~~~

It is used to return or display True if all the characters in the given


string must be alphabets only otherwise it will False

Syntax:
-------------

str.isaplha()

eg:

>>> str="PythonProgramming"
>>> x=str.isalpha()
>>> print(x)
True
>>>
>>>
>>>
>>> str="Python 3"
>>> x=str.isalpha()
>>> print(x)
False
>>>
>>>

isdigit()
~~~~~~~~~~~~~~~~

It is used to check the given string contains the digits only or not

If it contains digits it will return True otherwise False will return

Syntax:
-----------

str.isdigit()

eg:

>>> str="12345"
>>> x=str.isdigit()
>>> print(x)
True
>>>
>>>
>>> str="1234abcd"
>>> x=str.isdigit()
>>> print(x)
False
>>>

islower()
===========

It is used to return or display True if the given string contains only the
lower case characters

Syntax:
--------------

str.islower()

eg:

>>> str="hello"
>>> x=str.islower()
>>> print(x)
True
>>>
>>>
>>> str="Hello"
>>> x=str.islower()
>>> print(x)
False

isnumeric()
===============

It is used to return or display True all the characters in the given string
is numeric, otherwise False

This is applicable to Unicode objects only


Syntax:
~~~~~~~~~~

str.isnumeric()

eg:

>>> str="12345"
>>> x=str.isnumeric()
>>> print(x)
True
>>>
>>>
>>> str="12345abcd"
>>> x=str.isnumeric()
>>> print(x)
False
>>>

isspace()
==============

It is used to display or return True, if the given string contains all


whitespace characters only otherwise it will False

Syntax:
~~~~~~~~~~~

str.isspace()

eg:

>>> str=" "


>>> x=str.isspace()
>>> print(x)
True
>>>
>>>
>>> str=" hi "
>>> x=str.isspace()
>>> print(x)
False
>>>

istitle()
--------------

It is used to return or display True, if the given string contains the title
case otherwise it will return False

Syntax:
~~~~~~~~~~

str.istitle()

eg:
>>> str="Welcome To The Programming World"
>>> x=str.istitle()
>>> print(x)
True
>>>
>>>
>>> str="welcome to The Programming World"
>>> x=str.istitle()
>>> print(x)
False
>>>
>>>

isupper()
===============

It is used to display or return True, if the given contains upper case only
otherwise it will return or display False

Syntax:
~~~~~~~~~~~~~~

str.isupper()

eg:

>>> str="HELLO"
>>> x=str.isupper()
>>> print(x)
True
>>>
>>> x=str.isupper()
>>> print(x)
False
>>>

Filling Functions or Methods or Padding Methods or Functions


================================================================

center()
============

It is used to return or display the given string from the center

If the given string is completed then it is filled with a special character


which is given by the user

Syntax:
~~~~~~~~~~

str.center(width[,fillchar])

eg:

>>> str="Welcome to Programming World"


>>> x=str.center(50,'-')
>>> print(x)
-----------Welcome to Programming World-----------
>>>

ljust()
~~~~~~~~~~~~~~

It is used to display or return the given string in Left Justified manner

Syntax:
---------

str.ljust(width[,fillchar])

eg:

>>> str="hello"
>>> x=str.ljust(15,"@")
>>> print(x)
hello@@@@@@@@@@
>>>

rjust()
~~~~~~~~~~~~~~

It is used to display or return the given string in Right Justified manner

Syntax:
---------

str.rjust(width[,fillchar])

eg:

>>> str="hello"
>>> x=str.rjust(15,"@")
>>> print(x)
@@@@@@@@@@hello
>>>

zfill()
------------

It is used to display or return the given string & Left padded with zero(s)

Syntax:
~~~~~~~~~~~~

str.zfill(width)

eg:
>>> str="hello"
>>> x=str.zfill(15)
>>> print(x)
0000000000hello
>>>
>>>
>>>
>>> str="hello"
>>> x=str.zfill(5)
>>> print(x)
hello
>>>
>>>
>>>
>>> str="12345"
>>> x=str.zfill(10)
>>> print(x)
0000012345
>>>

You might also like