Advertisement



< Prev
Next >



Python - String isprintable() Method



The isprintable() string method returns True if the string's value is a printable, otherwise it returns False. The non-printable values are spaces, newline character \n, tabs etc.

Note : None of the string methods change the original string and only return a new string which reflects the change performed by the string method, hence the returned string must be stored or used(if needed to reflect the result), otherwise it is lost.



Signature of isprintable()


The isprintable() method has no parameters, so we don't have to worry about passing it some value.

# Signature of isprintable() method 
isprintable()





Let us see a few more examples of calling the isprintable() method on string of some non-printable values.

# Python - Method isprintable() Example



# Creating the first string of printable values
s1 = ('Lion King\n')


# Printing the first string
print('Value of first string  : ', s1)


# Calling  the upper() method on first string 
print('Calling the isprintable() method on first string : ', s1.isprintable())




# Creating the second string of printable values
s2 = ('Shawshank Redemption \n Forrest Gump')

# Printing the second string
print('Value of second string  : ', s2)


# Calling  the isprintable() method on second string  
print('Calling the isprintable() method on second string : ', s2.isprintable())




# Creating the third string of printable values
s3 = (' Avengers \t Endgame')

# Printing the third string
print('Value of third string  : ', s3)


# Calling  the isprintable() method on third string  
print('Calling the isprintable() method on third string : ', s3.isprintable())


Output is :


Value of first string  :  Lion King

Calling the isprintable() method  on first string :  False
Value of second string  :  Shawshank Redemption 
 Forrest Gump
Calling the isprintable() method on second string :  False
Value of third string  :   Avengers 	 Endgame
Calling the isprintable() method on third string :  False


Program Analysis







Please share this article -





< Prev
Next >
< String isidentifier() Method
String startswith() Method >



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement

Notifications



Please check our latest addition

PYTHON and DJANGO


Advertisement