RUVIDEO
Поделитесь видео 🙏

String Slicing : Python tutorial 12 #tiktokgirls #trending

📁 Обучение 👁️ 16 📅 02.12.2023

String Slicing : Python tutorial 26



Indexing and Slicing in Python
Strings are an ordered collection of letters, numbers and symbols which we can actually access each of these by their position(indexing) in a string. We can access a group of letters by slicing. In this tutorial, we will cover indexing and slicing a string in Python as one since they go hand in hand in Python.

Indexing in Python
Indexing provides each character contained in a string an identity so we can access that character or characters via slicing. The index always starts at the number 0 and counts up till the end of the string. Each character, space, symbol, and the number is automatically assigned an index number.

Example of a String Index


In the above example, we see how a string is indexed. You may have noticed the count start at 0 so this means that the letter T is at the 0 index. Then the index counts up from there including spaces and symbols.

Example How To Access a character via Indexing

#Indexing from the left side
a = 'This is a string'
a[0]
'T'

#Indexing from the right side
a = 'This is a string'
a[-1]
'g'
In the above example, we created a string and assign it the name(variable) of a. On the next line we index from the left to obtain the first letter in the string. Notice that we use zero to get the first letter in the string. If we just wanted to get the second letter, then it would look like a[1] to get the h. In the second example, we index from the right using a negative index number. We get the g at the end of the string. Negative numbers count backwards. When we index from the right or the end we do not begin with 0 we actually start with -1.

Here Are a Couple More Examples of Indexing

b = 'A new string for us to use'
b[1]
' '
b[4]
'w'
b[6]
's'
b[-4]
' '
b[-7]
' '
b[-6]
't'
Slicing in Python
In above section, we looked at indexing where we can only access one character at a time. Slicing gives us the ability to access a group of characters or a group of characters by skipping(stepping). Same rules apply positive number starts from the left and a negative number starts from the right. Let's look at some examples of slicing.

Our String For Theses Examples

#Our String for Slicing Examples

a = '0123456789'
Example a[1:5]

a = '0123456789'
a[1:5]
'1234'
In the above example, we slice from the first index which in this case is the number one and slice up to but not including index of 5. Let's break it down more "a" is name(variable) for the object then we have the opening square bracket which either indicates indexing or slicing then we have the number 1 which indicates index of 1 which is the starting point then a colon(:) which indicates we are slicing then we have the number 5 which instructs Python to stop at the index before the number 5 which is the fourth index position. Some new programmers get confused with the ending point in a slice which stops one spot before the number I give when writing the code. Hope that does not confuse you.

Example a[2:]

a = '0123456789'
a[2:]
'23456789'
In this example, we slice but we do not give an ending index so what happens. Python will start at the beginning index and count up to the end of the string. In this case, Python starts at the second index and continues to count up to the end of the string.

Example a[:7]

a = '0123456789'
a[:7]
'0123456'
In this example, we slice from an index of zero up to an index of 6 because the ending index always finishes one index position before we stated in the code. If we do not provide a starting index position like in above example Python will start index 0 and count up to the ending index.

Example a[0:-1]

a = '0123456789'
a[0:-1]
'012345678'
In this example, we slice from the start of the string up to but not including the last number. Remember negative numbers count from the right starting at -1. We could have also wrote this like this a[:-1] and we would have got the same result. Try it.

Example a[:]

a = '0123456789'
a[:]
'0123456789'
In this example, we basically just make a copy of the object that we just sliced. We provide no starting and ending index so we just get a copy of the string.

Stepping Through a String

We are going to add a third limit to our slice this limit allows us to step or skip through our string. Let's take a look at some examples.

a = '0123456789'
a[0:9:2]
'02468'
What happened in this example? Well we slice from the 0 index and then end at 8 index(9 is what we coded but always one before) and then we step through string by 2 this is the third limit we have added.

keyword:
python for beginners
python tutorial
python hindi
python tutorial in hindi
indexing in python
slicing in python
indexing in python hindi
indexing in python in hindi
slicing in python hindi
slicing in python in hindi
python hindi tutorial
python for beginners tutorials
indexing and slicing in python
indexing and slicing of string
alok python
alok python tutorials
python by alok raja

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «String Slicing : Python tutorial 12 #tiktokgirls #trending», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.