Python string slicing ✂️

preview_player
Показать описание
Python string slice tutorial example explained

#python #slice() #slicing

# slicing = create a substring by extracting elements from another string
# indexing[] or slice()
# [start:stop:step]

name = "Bro Code"

first_name = name[:3] # [0:3]
last_name = name[4:] # [4:end]
funky_name = name[::2] # [0:end:2]
reversed_name = name[::-1] # [0:end:-1]

print(reversed_name)

slice = slice(7,-4)

print(website1[slice])
print(website2[slice])

––––––––––––––––––––––––––––––
Creative Commons — Attribution-ShareAlike 3.0 Unported— CC BY-SA 3.0
––––––––––––––––––––––––––––––
Рекомендации по теме
Комментарии
Автор

# slicing = create a substring by extracting elements from another string
# indexing[] or slice()
# [start:stop:step]

name = "Bro Code"

first_name = name[:3] # [0:3]
last_name = name[4:] # [4:end]
funky_name = name[::2] # [0:end:2]
reversed_name = name[::-1] # [0:end:-1]

print(reversed_name)


slice = slice(7, -4)

print(website1[slice])
print(website2[slice])

BroCodez
Автор

Bro!!! You are the fourth video I watched on the slice operator, they all failed to answered the questions I had. You sir, have answered all my questions! Subscribed. :)

paticruz
Автор

Thanks for explaining indexing and the slice function. I’m taking an online course and they really didn’t explain. The negative numbers I liked, followed, and commented. Keep them coming.

pcn
Автор

Very concise. Python docs were confusing me on this and you really helped. Appreciate it.

ChristopherRichardson-sevb
Автор

Your videos are tremendously helpful. I've been tearing my hair out learning from a course today but your videos makes so much more sense. Thank you!

ycjade
Автор

Heavenly send. Clear explanation.
I love your videos.

carolinesemele
Автор

I start to understand everything, thank you so so much :) You are really good in teaching and its great video (all of them).

kawiurka
Автор

Thanks for walking us through this. I am just starting to learn how to code with Python and seeing you do this was really helpful. You have a new subscriber.

mauricelee
Автор

excellent explanation of negative indexing in slicing section. A+

JasonJorgensonPhD
Автор

Learning Python- thanks for posting-enjoyed the tutorial

jecdopl
Автор

Thanks man. Watching this right before my test

famousfighter
Автор

Thanks dude the exclusive part was messing with me when I started with array.

CarbonST
Автор

Is there any situation where we would need to ONLY use either indexing or slicing. Or are both interchangeable?

shon
Автор

commenting because you asked so nicely

mauipomare
Автор

you make everything really simple to understand Bro thanks

newperson
Автор

bro, something wrong with my code. When i copy slice=slice(7, -4), it returns str is not callable. How can I fix it?
tk u

minhquannguyen
Автор

thanks i learned a lot and i hope to complete it all

youtubego