-1

I'm trying to make my Python read only the first 3 digits of a string and print an answer based on the first three digits of the string.

I tried:

if str[1,2,3] = 080:
   print(...)
elif str[123] =090:
   print(,,,)
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
I Puchik
  • 1
  • 1

1 Answers1

0

use the index between the subscript like:

str[0:3] or str [:3]

this will take the cursor from 0th index to 2nd index

Masoom Raza
  • 125
  • 1
  • 17