The IS_CHARACTER_JUNK() function of Python difflib library

The function IS_CHARACTER_JUNK() checks whether a character is a junk character in the context of difflib library. The function considers the space and hash("#") characters as junk.

Difflib Module Updated 10 Apr 2026 1 min read

Overview

  • The function IS_CHARACTER_JUNK() function considers the characters space “ ” and “#” as junk and returns True when one of them is passed as the value for the parameter ch.

Example

python
# Example Python program that checks

# whether a character is a junk in the

# context of the difflib module

import difflib

testChar = '%'

isJunk = difflib.IS_CHARACTER_JUNK(testChar)

print("Is character \'{}\' junk:{}".format(testChar, isJunk))

testChar = ' '

isJunk = difflib.IS_CHARACTER_JUNK(testChar)

print("Is character \'{}\' junk:{}".format(testChar, isJunk))

Output

Output
Is character '%' junk:False

            Is character ' ' junk:True