Python Tutorial for Beginners 8 - Python Slices or Slicing

preview_player
Показать описание
In this video I am going to show How to use Slice function or slicing with Python Collections. Also I am going to show how to use Negative index with Python Collections. So What is Python Slice? A slize is a span of items that are taken from a sequence
List slicing format: list[start : end: step]. Span is a list containing copies of elements from start up to, but not including, end
If start not specified, 0 is used for start index. If end not specified, len(list) is used for end index. Slicing expressions can include a step value and negative indexes relative to end of list.
And What is Negative Indexing In Python: I a Python Collection such as Lists, Strings, Tuples, Bytes .. we can refer to an element by a negative index representing how far it is from the end.
example
# +---+---+---+---+---+---+
# | P | y | t | h | o | n |
# +---+---+---+---+---+---+
# 0 1 2 3 4 5 ---- Positive Index
# -6 -5 -4 -3 -2 -1 ---- Negative Index

★★★Top Online Courses From ProgrammingKnowledge ★★★

★★★ Online Courses to learn ★★★

★★★ Follow ★★★

DISCLAIMER: This video and description contains affiliate links, which means that if you click on one of the product links, I’ll receive a small commission. This help support the channel and allows us to continue to make videos like this. Thank you for the support!

- Python Slices
python tutorial for beginners pdf
python tutorial for beginners with examples
best python tutorial for beginners
python tutorial for beginners ppt
python tutorial for beginners video
basic python tutorial for beginners
learn python tutorial
Verwandte Suchanfragen zu python slices
python string multiple lines
python slice list
python string slice
python länge einer liste
python multiple assignment
python string to tuple
python string abschneiden
python compare tuples
Рекомендации по теме
Комментарии
Автор

Hats off to "ProgrammingKnowledge". You have done a great job. You made the programming piece of cake for beginners and boost their confidence in learning programming. I have watched and learnt programming by watching your videos. They are great. :-)

samcs
Автор

You are the best programmer as well as programming teacher.

rudramishra
Автор

Thanks bro..!!!
You are doing really awesome work...!!
Learned a lot from your videos..!!!

pravinbaste
Автор

its useful to us till now .... love it

fathimajesrin
Автор

for better experience, efficiency and speed watch at 2 times the original speed and i believe most of you will be able to withstand but for those of you who can't take this speed (assuming it's fast which it isn't) after some time(2 minutes) slow down to 1.5 and that will be easily understandable

vivekpannu
Автор

this is more like using terminal in linux than programming nice tutorial u explain so much i really appreciate for it

LtMewS
Автор

thank you formaking these! they are such a great :)

sofiachildress
Автор

i think in case of [-4:-2]it will first goes to -4 from the end and then print diff of given no value i.e(in this case it will print 2 values as 4-2=2 )starting from -4 value.

SinghTheSoftware
Автор

While using my list [0: :3], it doesn't skip, but it prints the 3rd value. It skips 2 values and print 3rd. Your videos are too helpful in understanding python. Thank you so much.

sunildingankar
Автор

Guruji, thanks for your videos, its really helping me a lot although I am not a techie

RajashekarNarayana
Автор

Thank you for these videos. I've learned so much

wesleysimpson
Автор

Hi, very good tutorial. Thank you.
I have tried this also mylist[ : : 0] will give us error since slice step cannot be zero.
And I will keep watching your video. Really helpful.

shankarsalesforceseries
Автор

sir, can u please explain the concept of 6:54, i am not able to get that.

saurabhbhathiza
Автор

on the slicing on the mylist[] wanting to show 5 thru 9 .. you suggested using why not use mylist[5:]
It shows the same output.

brgarrison
Автор

At 6:56 in the video myList [-4:-2], why does it not print 8 and skips to print 7, but then it goes back and prints out 6 and doesn't print 7 again instead. Because it seems that it skipped -2 first to print 7, but it doesn't skip -4 and prints 6?

Does anyone have an explanation for this?

thuyvuong
Автор

4:56 it didnt skip the 3rd value. C is the third value and it was printed.

rafaeljuca
Автор

you are making some confusion my friend with numbers and idexes. In the first example, for instance, [4:8] 4 here correspond to the fourth position which is number 3..for some reazon it skipes the first index number asked and prints the next one in this case number 4 corresponding to the 5th index position and it goes until the 8th position in which displays the number 7. when You've created by the next mylist index [5:10] this 10 does not reffer to the number 10 that might come after the number 9 on the list but 10 here is the 10th position that belongs to list number 9. number 0 holds the 1st position.

rafaeljuca
Автор

not sure if I missed this part but what if you want to list all but exclude 1 slice.

professordd
Автор

it is not necessary to print till end we need to give mylist[4:10]
even we give mylist[4:29], it will give same answer.
my way seems to be rude but i am simply identifying different ways and bluntly typing is down

rajkumarkushwaha
Автор

Great job ProgrammingKnowledge!!
I think I found a minor bug in Python related to this lesson.
When you print(mylist[9:11]), it prints 9, however names[11] is out of range. I was hoping for an error but it didn't throw any. If I try to explicitly print(mylist[11]), it does throw an error !!

neerajn