Printing from range number to a letter

3797 views python
5

Hi I am quite new to Python and I am unsure of how to print from a number to a letter, if suppose I do not know the position of a particular letter.

For example: 'clay' print (0:'y')

and it should print out 'cla.'

answered question

You mean substring? like print('clay'[:3])?

1 Answer

6

v = 'clay'
print(v[:v.find('y')])

posted this

Have an answer?

JD

Please login first before posting an answer.