Python Programming Tutorial #11 - Slice Operator

preview_player
Показать описание
This is the 11th video in my python programming series. In today's video I talk about the the slice operator. The slice operator can be used on strings and lists.

As always please LIKE and SUBSCRIBE for more content.

Video Tags:
python,python tutorial,python language,python full course,python course,learn python,learn python programming,python tutorial for beginners,python tutorial 2018,python programming tutorial,python programming language,software development,programming tutorial,techwithtim
Рекомендации по теме
Комментарии
Автор

It will insert each letter like a one item of a list, because string is also a list. You can also insert a list into another list.
So, if you make the string you want to insert an item of a list ['BlueBerry'] it will insert the whole word as one item:
fruits[2:2] = ['BlueBerry']

When you want to insert a number like this, it also must be an item of a list. Otherwise it will make an error.
fruits[3:3] = [5]

It can be inserted more items at once:
myList = ['a', 'b', 'c']
myList[1:1] = ['one', 2]
-> myList will be ['a', 'one', 2, 'b', 'c']

eliskapilatova
Автор

great video but you have been spelling strawberries wrong but seriously thanks for the help

lewismailey
Автор

Thank you very much Tim, for making these kind of videos for beginners. I would also mention the insert method here, but overall it was really great.

barnabasbor
Автор

"Let's spell that correctly: "blueberrys"" xD
I died at that moment

rafascisowski
Автор

In your text-based tutorial, it should be myList[1:1] = [-40] in insertion using slice part

arifbasri
Автор

fruits[2:2] = 'BlueBerry';
print(fruits);
why does it make a list part of each letter?

DeadManRising
Автор

while adding a fruit name in the list say papaya instead of b, output included each letter separately, can you suggest the modification. Output example ['apples', 'p', 'a', 'p', 'a', 'y', 'a', 'bananas]
Code:
fruits = ['apples', 'bananas']
fruits[1:1] = 'papaya'
print(fruits)

AyushKumar-gpys
Автор

Nice video
Watched at 2x
Meet you in next one

eswarspython
Автор

Instead of 'b', i used 'tomatoes'

fruits[0:0] = 'tomatoes'

['t', 'o', 'm', 'a', 't', 'o', 'e', 's', 'apples', 'pears', 'strawberries', 'blueberries']

what'd I break?

daveruble
Автор

r u kidding me? u don't need for loops to print out lists?

mephystto
Автор

i typed banana instead of b, and it turns out 'b', 'a', 'n', 'a' and so on

wongkingshun
Автор

Why use slice operators for a list rather than .insert(), beyond being shorter?

mikeb
Автор

Great video! I've been testing a few things while watching it and i found out that if you write:
fruits[1:2] = "b" It replaces the item in te second position
fruits[1:3] = "b" it replaces the item in the second position and deletes the item in third position

do you guys know why that happens?

daniel_dominguezs
Автор

Strawberries and blueberries 😉 Also Python works differently now and this video will no longer produce the results specified.

methodraw
Автор

great video but i have a question
why when i add a sentence using this method to the beginning of my list it all comes out every letter seperated ?

AmirShooshtarian
Автор

I have watch the 6 hours long version, so it feels like a revisoin to me.
I think i know the content, but forgot this is call slice operator.

wongkingshun
Автор

425 likes, 1 dislike... WOOWWWW who disliked btw 😡😠💢👿👿

idhantsood
Автор

The devil took the first slice of his birthday cake. There was something written on it. HELL. He smiled and ate it... (in case if you have zero sense of humor or your just dumb the first time he sliced, the output was HELL)

basicallybrand