• Skip to primary navigation
  • Skip to content
  • Skip to footer
Arshad Mehmood
  • Today I Learned
  • Portfolio
  • Contact
    1. Home
    2. /
    3. Today i learned
    4. /
    5. Python
    6. /
    7. Strip non-alphabetical or non-alphanumeric characters in a string
    Arshad Mehmood

    Arshad Mehmood

    Software engineer for web and mobile. M.Sc. Business Informatics, University of Mannheim.

    • Mannheim, Germany
    • My Android Apps
    • Website
    • LinkedIn
    • GitHub
    • Twitter
    • Instagram

    Strip non-alphabetical or non-alphanumeric characters in a string

    less than 1 minute read

    Strip non-alphabetical or non-alphanumeric characters in a string

    Python characters have a function isalpha() and isalnum() which can be used to strip non-alphabetical or non-alphanumeric characters in a string.

    s = ''.join(x for x in s if x.isalnum())
    s = ''.join(x for x in s if x.isalpha())
    

    Share on

    Twitter Facebook LinkedIn

    Leave a comment

    • Follow:
    • Twitter
    • GitHub
    • Instagram
    • Feed
    © 2025 Arshad Mehmood. Powered by Jekyll & Minimal Mistakes.