Python String isprintable Method - Python Tutorial | Logic Practice
Python Course / Data Types / Python String isprintable Method

Python String isprintable Method

BLUF: This lesson on Python String isprintable Method provides a comprehensive guide to understanding and implementing this concept in Python. Whether you're a beginner or looking to refresh your knowledge, you'll find clear explanations and interactive code examples here.
Key Concept: Python String isprintable Method

Mastering Python String isprintable Method is essential for building efficient Python applications. Focus on the syntax and the best practices highlighted in this tutorial.

The Python method isprintable will return True if every character within the string is printable, or if the string is empty. Conversely, it will yield False if any character in the string is classified as Nonprintable.

Syntax of Python String isprintable Method

It has the following syntax:

Example

isprintable()

Parameters

No parameter is required.

Return

It returns either True or False.

Different Examples of Python String isprintable Method

Let's examine a few examples of the isprintable method to gain a better understanding of its features and capabilities.

Example 1

Here is a straightforward illustration that outputs True when the string can be printed. Refer to the example provided below.

Example

# Python isprintable() method example

# Variable declaration

str = "Hello, World"

# Calling function

str2 = str.isprintable()

# Displaying result

print(str2)

Output:

Example 2

In this section, we will incorporate additional characters such as newlines and tabs within the string. Observe the outcomes from the example provided.

Example

# Python isprintable() method example

# Variable declaration

str = "Hello, World"

str2 = "Learn Python here\n"

str3 = "\t Python is a programming language"

# Calling function

str4 = str.isprintable()

str5 = str2.isprintable()

str6 = str3.isprintable()

# Displaying result

print(str4)

print(str5)

print(str6)

Output:

Output

True

False

False

Example 3

Evaluating various string inputs that include special characters as well. When special characters are present, the method will return False.

Example

# Python isprintable() method example

# Variable declaration

str = "Hello, World"

if str.isprintable() == True:

    print("It is printable")

else:

    print("Not printable")

str = "$Hello@C# Tutorial#"    # Special Chars

if str.isprintable() == True:

    print("It is printable")

else:

    print("Not printable")

str = "Hello\nHelloworldvisualizer"

if str.isprintable() == True:

    print("It is printable")

else:

    print("Not printable")

Output:

Output

It is printable

It is printable

Not printable

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience