हिंदी

The code provided below is intended to remove the first and last characters of a given string and return the resulting string. However, there are syntax and logical errors in the code. - Computer Science (Python)

Advertisements
Advertisements

प्रश्न

The code provided below is intended to remove the first and last characters of a given string and return the resulting string. However, there are syntax and logical errors in the code.

Rewrite it after removing all the errors. Also, underline all the corrections made.

define remove_first_last(str):
   if len(str)<2:
      return str
   new_str = str[1:-2]
   return new_str
result = remove_first_last("Hello")
Print("Resulting string:"result)
वाक्य को सही करें और फिर से लिखें
Advertisements

उत्तर

def remove_first_last(str):
  if len(str)<2:
      return str
  new_str = str[1:−1]
  return new_str
result = remove_first_last("Hello")
print("Resulting string:",result)

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2025-2026 (March) Board Sample Paper
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×