number extractor

    0

    0

    Mahendra Kumar

    beginnerstringsnumbers

    Python program to extract number from string

    # take string
    string = "2 Java developer and 5 Python developer"
    # print original string
    print("The original string:", string)
    # using str.split() + isdigit()
    num = []
    for i in string.split():
        if i.isdigit():
            num.append(int(i))
    # print extract numbers
    print("Extract Numbers:", num)
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.