#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    6
    Rep Power
    0

    String and regexp


    Hi
    I am very new to python and have a simple task -
    Given a string "0x8bb860" I need to determine if if starts with the characters "0x"

    I have tried

    x = "0x8bb860
    print x.startswith("0x")

    but this gives me an exception

    How is the correct way to do this?

    Thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Location
    Joensuu, Finland
    Posts
    431
    Rep Power
    67
    Originally Posted by grahamlabdon
    How is the correct way to do this?
    Add the ending double quote and, if you are using Python 3, use parentheses:

    Code:
    x = "0x8bb860"
    print(x.startswith("0x"))
    My armada: openSUSE 13.1 (home desktop, home laptop), Crunchbang Linux 11 (mini laptop, work laptop), Android 4.2.1 (tablet)
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    6
    Rep Power
    0
    Thanks

IMN logo majestic logo threadwatch logo seochat tools logo