Python string slicing ✂️
ฝัง
- เผยแพร่เมื่อ 6 ต.ค. 2024
- 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)
website1 = "google.com"
website2 = "wikipedia.com"
slice = slice(7,-4)
print(website1[slice])
print(website2[slice])
------------------------------
Up In My Jam (All Of A Sudden) by - Kubbi / kubbi
Creative Commons - Attribution-ShareAlike 3.0 Unported- CC BY-SA 3.0
Free Download / Stream: bit.ly/2JnDfCE
Music promoted by Audio Library • Up In My Jam (All Of A...
------------------------------
# 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)
website1 = "google.com"
website2 = "wikipedia.com"
slice = slice(7,-4)
print(website1[slice])
print(website2[slice])
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. :)
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.
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!
yeah I don't know the first thing about coding and all the videos I found assumed you knew the fundamentals. I even went so far as to start watching 'coding for kids' videos, but what this guy is doing is amazing! Breaking everything down from the very first steps, this dude is a legit bro.
Very concise. Python docs were confusing me on this and you really helped. Appreciate it.
I start to understand everything, thank you so so much :) You are really good in teaching and its great video (all of them).
Learned a lot. Thanks for the video.
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.
Heavenly send. Clear explanation.
I love your videos.
😂
Thank you for your TH-cam algorithm😌
Thanks dude the exclusive part was messing with me when I started with array.
Thanks man. Watching this right before my test
thanks alot, this really helped
excellent explanation of negative indexing in slicing section. A+
Learning Python- thanks for posting-enjoyed the tutorial
Is there any situation where we would need to ONLY use either indexing or slicing. Or are both interchangeable?
you make everything really simple to understand Bro thanks
thanks i learned a lot and i hope to complete it all
अतिसुन्दर,,,,,,,
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
Thank you bro❤️
Excellent lecture
Learnt a lot, really thanks!
excellent tutorial !
Awesome clip. Thanks that really helped
The entire lesson is clear and easy to understand. But I have a small question, is it possible that the index function could be set to a character such as a space or a comma and not to a letter position in a line. For example, I am doing input, please enter the first name and last name, so that index is to the first name to a space and index to the second name from a space.
You can use find( )...
name = input("Enter ur name : ")
hi = name.find(" ")
slice = slice(0, hi)
if hi == -1 :
print (f" Your first name is {name.capitalize} ")
else:
print (f" Your first name is {name[slice].capitalize()}")
😄
Thanks,it was a helpful tutorial
Good video bro
Thank you!
Thanks Bro
thank you for the lessons!
thank you! super helpful!
ez to understand. Ty!
great video
Thanks for sharing
Thanks
Nice
nice
Hello I have a question with the slice function index -4 is exclusive or inclusive. Thanks
[1:-4] its exclusive, [-4:-2] inclusive
WOhooooooo BRO CODE
start stop step ahh u are nice thanks
INFORMATIVE!
Great vídeo bro
u r gr8
commenting because you asked so nicely
Excellent!
Marvelous
Thanks for the video
Thx!
Hey, thank you!! :)
thanks bro
thnx bro!
It is great !
bro is nice with the code
Thank you bocd 💙💙
Can you make a tutorial on pygame plzzz sir
exlent tuto I apreciate
Hey Bro, I use the Google colab to program. When I'm trying to use slice function, the system told me that "'slice' object is not callable" I'm wondering why?
yeah but how do you reverse a sentence, without reversing the letters within
i just get this error message that its not working. im sitting here for 30 minutes now :(
You are great 👍👍😽👍🙏🙏
thank you
Tks bro
thanks
is your name really bro code?
bruh you really asking?
Why is it that when I write my code exactly as he does I get an error saying that 'sllice' object is not callable. In order to see it was not my fault, a copy and pasted the code exactly from the description and still got an error.
I was using Google colab when I got this error but I did not get this error when I downloaded pycharm and wrote the code in there. Why?
now PyCharm is no more tolerant to variables' names same as the function's.
So rename that "slice" var into... say, "slicee"
master
perfect
Ey bro.. thanks
eDoc with the orb
Were did you learn python
Try
Ty
i didnt understand the output of funky_name = name[::2]. can someone explain to me pls, i understand that the default is 1 but i dont get the 2 and 3
Basically, the number that you put after the second colon (the step) is how many indexes of the string the compiler will increment(or decrement by, if the value is negative) when slicing the string. In the case of funky_name, since the step value is 2,
every other letter in the name is printed because the index will be going up by 2 instead of the default 1. Hope this helps.
noice
Thanks edoC orB
shout out to people that just press the like button for bros videos, just because
bro can you create josh clone
Why am I getting invalid syntax
It wasn't a good idea to use the name for the variable "slice" same as the function's "slice ()"
👍
❤️
Hey bro this video no Chinese cc >
I think bro code eated alot of brocoli s
Broooo
youtube algorithm comment
Bro
hell💀
t u
Great Video
cool
Thanks
Nice
thanks!
Thanks
Thanks
Thanks bro