How to replace dots in Python?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sarp ka
    New Member
    • Nov 2011
    • 1

    How to replace dots in Python?

    Here's the question I need to replace '.'s with a word such as 'DOT' which will be defined lets say to replace_dots,
    So when I use
    replace_dots 'hello.'
    It should print out
    helloDOT
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Use string method replace().
    Code:
    >>> s = ".abcdef"
    >>> s
    '.abcdef'
    >>> s.replace(".", "?")
    '?abcdef'
    >>>

    Comment

    • Ephexeve
      New Member
      • May 2011
      • 20

      #3
      Regular expressions would be a option too

      Comment

      Working...