Strings Slicing and Operations on Strings in Python | Python Tutorial - Day #12

preview_player
Показать описание
Python is one of the most demanded programming languages in the job market. Surprisingly, it is equally easy to learn and master Python. This python tutorial for absolute beginners in Hindi series will focus on teaching you python concepts from the ground up.

python, C, C++, Java, JavaScript and Other Cheetsheets [++]:

►Learn in One Video[++]:

►Complete course [playlist]:

Follow Me On Social Media
Comment "#HarryBhai" if you read this 😉😉
Рекомендации по теме
Комментарии
Автор

nm="Harry"
print(nm[-4:-2])
*The length of the string is 5, and the order of characters starts from zero, so H(0), a(1), r(2), r(3), y(4).
Back to the code;
(len(nm)-4-->5-4=1
(len(nm)-2-->5-2=3
*Hypothetically new statement is print(nm[1:3])
we know the starting point is 1, but to access the character's order we use n-1 principle.
So, order of character=n-1
OC=3-1=2
Take the order of characters from 1 to 2 from the actual string; hence, the output is (ar).

arslanahmed
Автор

I haven't installed Instagram!!

Ans= ar
Here, print(nm[-4:-2]), means that, nm is of 5 characters therefore 5-4= 1, and 5-2= 3....
It will be like this •print(nm[1:3]), including 1 and not 3!!
Thanks HarryBhai!
#100 days of code

sanskar_
Автор

10:38 / 11:47
THE OUTPUT WILL BE = "ar"'
thank you harry bhai
for this amazing course .😃

unknownerror-tu
Автор

the answer is ar because 5-4: 5-2 which is equals to 1:3 and as the third index is ignored and starts from 0 your output is "ar".
and thank you for your nice explanation .

Agrim
Автор

Day #12 done! Thanks to Almighty I was able to complete today's lecture even though I'm very sick right now.

vickyaryanvlog
Автор

#Quickquiz Answer - ar
Explanation - len(nm)=5
5-4:5-2 gives 1:3 python will only give till second index i.e. ar
#Harrybhai

Anshuman_
Автор

Lecture revision:
strings are just like an array of characters so we can access each of those characters. len(obj) gives the total length. to splice a string code is string[0:5]. 0 can be omitted, 5 if omitted will result in complete string be printed. negative splicing means that it will subtract the index from total length of string . string[0:-3]

sohailnawaz
Автор

# Quick quiz
nm="Harry"
print(nm[-4:-2])
# total length 5
# 5-4=1
# a sa shuru ho ga 1 sa aga gina cursor dekh ka
# 5-2=3 three sa aga nhi gina jai ga
# answer is ar
sir present lots of love from pakistan sir g answer phla comment ma likha phir run kr liya tha thank you theekn answer aya mara

tombyter
Автор

Hi harry bhaiya, i completed your C Language full course which was great and easy to understand. Now i am doing this course as i want to learn AI . You are the best i should say in teaching of Programming . Thanks a lot for all that you are giving us free of cost also in "Desi bhasha".❤

ROCKY_
Автор

1st time koi playlist consistently follow kr rha hu roj 15 minute
To see the power of consistency what I achieve after 100 days 🔥🔥🔥

anuragsingh-
Автор

Day3 of #100DaysOfCode. In this video 12, I learned about string slicing and operations in Python. I discovered how to find a string's length using the len() function, access characters with indices, and perform slicing to extract parts of a string. Additionally, I learned that strings are iterable arrays, allowing me to loop through their characters.
Thank You Harry Bhaiya.

debasishbesra
Автор

# nm = "Harry"
# print(nm[-4:-2])

Output:
ar
len(nm)-4 and len(nm)-2 [1, 3] prints ar(excluding the alphabet at index 3)

utkarshsahay
Автор

nm = "Harry"
01234
print(nm[-4:-2])
will be equal to 5 - 4 = 1 and 5 - 2 = 3
[1:3]
that is " ar " as 1 will be count and 3-1 will be counted.
Thank you Harry Bhai🤝

divyanshutiwari
Автор

nm="harry"
print(nm[-4:-2]) sring ka length =5 so 5-4=1 and 5-2 =3
order of character stars from 0 so print(nm[1:3]) including 1 and not 3
The output is "ar"...
thank you for this amazing video
#Day 12 complete

SoumyadipDas-obui
Автор

@Dine Vlogs
Present Harry Bhaiya 😊😊
The input is :- nm = "Harry"
print(nm[-4 : -2])
Out put= ar

EXPLANATION :--
Because the length of word is 5(H a r r y)
5-4 = 1
start counting to zero(0) 1= a
Second
5-2 = 3
start counting to zero(0) 3= r

dineshsoni
Автор

# quick quiz
nm = "harry"
print(nm[-4:-2])
the answer is the ar

RehanPathan-
Автор

nm = "Harry"
print(nm[-4:-2])
The variable nm is assigned the string "Harry". The print() function is then used to display a portion of the string using slicing.

Slicing is a way to extract a substring from a string in Python. It uses the syntax string[start:end], where start is the index of the first character you want to include in the substring, and end is the index of the character after the last character you want to include in the substring.

In this case, nm[-4:-2] represents a slice of the string nm:

start = -4: The index -4 corresponds to the 4th character from the end of the string. In this case, it is "a".
end = -2: The index -2 corresponds to the 2nd character from the end of the string. In this case, it is "r".
So, the slice nm[-4:-2] includes all characters from the 4th character from the end ("a") up to, but not including, the 2nd character from the end ("r").

The result of print(nm[-4:-2]) will be the substring "ar". It is important to note that slicing in Python includes the starting index but excludes the ending index. Therefore, the character at index -2 ("r") is not included in the result. The slice includes characters at indices -4 and -3 ("a" and "r", respectively).

HamzaShahid-st
Автор

10:22
nm = "Harry" #length of Harry is 5.
print(nm[-4 : -2]) #output --> ar, because 5 - 4 = 1, 5 - 2 = 3 and 3 include nahi hoga, isliye 1 se 2 tak print karega

NishantKumar_N
Автор

[-4:-2] string slice anser is ar soln = 5-4=1, 5-2=3 then start is 1 and end is 3 index of string
ab=" harry"
print([ 1:3])

rajkamalkumar
Автор

100th comment🔥🔥
Thank you very much harry bhaiya
I am in class 9 and I have become a hero of coding in my school just because of you..

priyxnshu