First Come First Print!

    0

    0

    Mahendra Kumar

    beginnerstringsslicing

    Python Program get first n characters of the string

    # take string
    string = input('Enter any string: ')
    # take value of n
    n = int(input('Enter n: '))
    # get first n characters
    first_char = ""
    for i in range(0, n):
        first_char = first_char + string[i]
    # printing first n characters of string
    print('First', n, 'character:', first_char)
    
    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.