Index_slicing_problem

33 Views Asked by At

I have started learning Python today and I am facing a problem while doing "slice" in Python. I saw Brocod's video but after following him the problem wasn't solved.

website="http//google.com"
slice=slice(7,-4)
print(website[slice])

And The output I am getting:

[Running] python -u "d:\Learning\BroCode\Python\String_slice.py"
oogle

[Done] exited with code=0 in 0.505 seconds

I tried to rewrite the code, reinstalling Vs code but none of them worked.

1

There are 1 best solutions below

0
iFlo On

Read the doc carefully : https://www.programiz.com/python-programming/methods/built-in/slice

Your string index starts from 0 so g is the 7th index, which is 6.

You should do :

website="http//google.com"
slice=slice(6,-4)
print(website[slice])

to get google