# 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)
      

      Python language logo
      First Come First Print!

      beginner
      strings
      slicing

      Python Program get first n characters of the string

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.