Python Tutorial - Reverse a String Using for loop

  Рет қаралды 171,277

Amulya's Academy

Amulya's Academy

Күн бұрын

In this Python Programming video tutorial you will learn how to reverse given string .
Here in this video tutorial we will learn how to reverse a string using for loop and function in detail with example.
For more free tutorials on computer programming
/ amulsacademy
/ amulsacademy

Пікірлер: 284
@uday2339
@uday2339 6 жыл бұрын
n =("amuls") n1=(n[::-1]) print(n1)
@hemantprasad1018
@hemantprasad1018 5 жыл бұрын
there are 5 ways to reverse a string in Python
@marioshusband3700
@marioshusband3700 4 жыл бұрын
what does the (n[::-1]) mean? I barely learned python.
@40melcolmvaz55
@40melcolmvaz55 3 күн бұрын
​@@marioshusband3700 go check slicing of index of a string tutorial.
@papie5151
@papie5151 4 жыл бұрын
I love all your tutorials. I see often in the comments some smart code which for a beginner like myself means nothing- maybe,will be valuable in the future, but your tutorials are in depth which drives in my understanding of the programming concepts. Please keep doing what you are doing. Bless you.
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
Thank you so much :}
@riuspablo
@riuspablo 6 жыл бұрын
Or >>> string = "amuls" >>> string[::-1]
@bagavathi5340
@bagavathi5340 4 жыл бұрын
it's a simple method
@vortex_7574
@vortex_7574 4 жыл бұрын
Genius!
@vimukthiaravinda6288
@vimukthiaravinda6288 4 жыл бұрын
this is the right method
@jenre6903
@jenre6903 3 жыл бұрын
you just saved me 8 minutes. thank you, you are a legend
@soulfulman4834
@soulfulman4834 3 жыл бұрын
This is inbuilt method which I use oftenly but it doesn't works in complex programs...
@kapishsingh
@kapishsingh 6 жыл бұрын
def reverse(y): for i in range (1,1+len(y)): print(y[-i],end='') reverse("amulse")
@00xess
@00xess 4 жыл бұрын
why the hell did you pass in 1 at the first place, just use range(len(y)) lmao
@panagiotisgoulas8539
@panagiotisgoulas8539 4 жыл бұрын
@@00xess If he did that he would have to print(y[-i - 1], end=''). First index is 0 but last is -1
@thesumitkumar0
@thesumitkumar0 3 жыл бұрын
#run_this print(input()[-1::-1])
@kapishsingh
@kapishsingh 3 жыл бұрын
@@thesumitkumar0 you can ignore -1 in beginning
@sambhavsisodia3920
@sambhavsisodia3920 6 жыл бұрын
l,m,n = yell,yem,yen 😂😂😂 ,whatever video was great !
@AmulsAcademy
@AmulsAcademy 6 жыл бұрын
Thank you:)
@MuhammadNaeem-xj8zp
@MuhammadNaeem-xj8zp 4 жыл бұрын
Yeh it should be el, am ,an for l, m , n any ways great explanation nice voice
@rb8934
@rb8934 4 жыл бұрын
the pronunciation differs as per the state
@soumyashreebiswal14
@soumyashreebiswal14 3 жыл бұрын
@@MuhammadNaeem-xj8zp Its not about whether it SHOULD BE or whatever. Its totally okay to have a different pronounciation.
@chandanshivalingaiah9861
@chandanshivalingaiah9861 3 жыл бұрын
Nobodys perfect summbbbhaaavvvvvvvaaa ssuuusssoooddiiiaaaaa so please watch it or get out nobody wants you here anyway
@davidusharauli2227
@davidusharauli2227 6 жыл бұрын
How this code reverses the input string? It works but I am not sure if I understood the mechanics of it. Can you explain a little bit more.
@AmulsAcademy
@AmulsAcademy 6 жыл бұрын
def reverse(string): reversed_string = "" for i in string: reversed_string = i + reversed_string print("reversed string is:",reversed_string) string = input("enter the string:") print("entered string is:",string) reverse(string) Here first , string = input("enter the string") will be executed, so you need to enter the input, if you enter "amuls" this string will be stored in variable string Next it will execute , print("entered string is:",string) so it will print entered string to the output screen. Next it will execute function call that is, reverse (string) so now control goes to the reverse function definition, so it will execute that function. def reverse(string) here string is the input that is "amuls", next we will take one variable and we assign empty string to that. reversed_string = "" here reversed_string is a variable which will hold final output. next for loop, for i in string: reversed_string = i + reversed_string so here string is "amuls", so initially variable i value will be 'a', so it will execute for loop body , reversed_string = i + reversed_string here we are doing string concatenation, symbol + is used for concatenation of strings. reversed_string is initially empty string and i value is 'a' so it will concatenate 'a'and empty string, so we will get reversed_string as 'a' that is, reversed_string = i + reversed_string = 'a' + "" = 'a' next again control goes to for loop, now i value becomes 'm', it will execute for loop body, reversed_string = i + reversed_string = 'm' + 'a' = "ma" in this same way it will continue the execution:)
@Amit-nh2pu
@Amit-nh2pu 6 жыл бұрын
great!
@vengateshprasath2906
@vengateshprasath2906 6 жыл бұрын
Str="David" str[::-1]
@melissahuerta8315
@melissahuerta8315 4 жыл бұрын
thanks for the explanation, at first I was confused too.. reading the string as it was an array like str[I] and in my mind it got the same order.. but now is clear :)
@sultanahmadsabawoon6030
@sultanahmadsabawoon6030 4 жыл бұрын
still confused. make the code as reversed_string + i. in this case it will give you the same string as entered initially. the trick is that the i value is cancatenated with reversed string not the other way around.
@a42h
@a42h 6 жыл бұрын
Thank you this was very helpful! I like how you went into details of the for loop and explained the logic of it.
@AmulsAcademy
@AmulsAcademy 6 жыл бұрын
Thank you:)
@FI3RZE_PATRIOT
@FI3RZE_PATRIOT 4 жыл бұрын
@@AmulsAcademy GREAT VIDEO AND WELL EXPLAINED!!!
@vidithnarayana2346
@vidithnarayana2346 4 жыл бұрын
@@AmulsAcademy python code to reverse a string without effecting special characters?(Input: ab,c,d)(output:dc,b,a) please reply
@romantrenton3644
@romantrenton3644 3 жыл бұрын
You all probably dont give a damn but does any of you know of a method to get back into an Instagram account? I somehow lost my account password. I appreciate any tricks you can offer me.
@hunterjamal6970
@hunterjamal6970 3 жыл бұрын
@Roman Trenton Instablaster =)
@kishoredev6004
@kishoredev6004 4 жыл бұрын
def rev(x): return x[::-1] rev('forward')
@gamerjmax5568
@gamerjmax5568 3 жыл бұрын
x = input("Enter any name: ") x[::-1]
@klaskycsupo121
@klaskycsupo121 4 жыл бұрын
So chars are going to be concatenated from right to left? Did I get this right?
@GAURAV-xd1pi
@GAURAV-xd1pi 5 жыл бұрын
for all the idiots making fun of her pronunciation just don't watch the video, simple!
@balakarna_editz2779
@balakarna_editz2779 5 жыл бұрын
Nice explanation, please upload python data science videos
@gamingengineer360
@gamingengineer360 3 жыл бұрын
now thats what I call explanation. a k.g. boy can understand the program. thanq mam.
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you :)
@ralphmachado8201
@ralphmachado8201 5 жыл бұрын
hi i learn a lot from your videos and check my below code which is more simply than the above one. print("enter anything to be reversed") x=input() length=len(x) for i in range(length-1,-1,-1): print(x[i],end="")
@PassionateSaksham
@PassionateSaksham 4 жыл бұрын
What the Meaning Of -1,-1,-1 Here Please Answer Me
@ralphmachado8201
@ralphmachado8201 4 жыл бұрын
@@PassionateSaksham 1: length-1 means that the for loop will start from the index number which is one less than the length of the string to be reversed 2: -1 is the number untill which the for loop will run 3: -1 is the amount which will be decremented after every iteration and this will continue until the number reaches till -1.
@v.vijayaprathaban7017
@v.vijayaprathaban7017 3 жыл бұрын
Input:Python Output:NOHtyp In output first 2letters are caps, then what i do? This is task in my college... If any one do this?
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
After reversing the string, slice the string [ first 2 char and rest char] then use upper function for first substring then concatenate :)
@thesumitkumar0
@thesumitkumar0 3 жыл бұрын
#shortest program for printing reverse string print(input()[-1::-1]) or print(input()[::-1])
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
😊😊
@NewIndianera
@NewIndianera 6 жыл бұрын
Mam make video for those who don't know anything about programing even ABCD of it
@NewIndianera
@NewIndianera 6 жыл бұрын
Mam make video on c++ and html and core and advance java
@sunny14o4-2k
@sunny14o4-2k 6 жыл бұрын
wrd=input("Please enter a word") wrd=str(wrd) rvs=wrd[::-1] print(rvs) if wrd == rvs: print("This word is a palindrome") else: print("This word is not a palindrome") "could you explain this"
@AmulsAcademy
@AmulsAcademy 6 жыл бұрын
This program is to reverse the entered string and to check whether it is palindrome or not. 1. wrd=input("Please enter a word") you are asking user to enter the string and it will be stored in variable wrd. 2. wrd=str(wrd) if you are using python 3 then no need to write this line. here you are converting entered input to string, but in python 3 by_default whatever the input you enter it will treat that as string. 3. rvs=wrd[::-1] here it will reverse the string. you are using slicing operation here . syntax of slicing is string_name[start:end:step] start - starting integer where the slicing of the object starts. stop - integer until which the slicing takes place. The slicing stops at index stop - 1. step - integer value which determines the increment between each index for slicing. In the above program you didn't mention start and end so it will take entire string. -1 is the step . So, when you do string_name[::-1] , it starts from the end, towards the first, taking each element. So it reverses the string. 4. print(rvs) you are printing the reversed output. 5. if wrd == rvs: print("This word is a palindrome") else: print("This word is not a palindrome") in this if else condition you are checking whether the entered string is palindrome or not. A string is said to be palindrome if reverse of the string is same as string. that's why we are checking wrd==rvs here wrd is the entered input or original string rvs is reversed string if both are same then the string is palindrome if not then not a palindrome. :)
@dabhijaydeep
@dabhijaydeep 3 жыл бұрын
Can u make decorator using reverse number and also negative number and also string enter to string reverse in single function
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Will try 😊
@raheemabdul4410
@raheemabdul4410 4 жыл бұрын
U seem kannadiga from Bangalore..lots of wishes from mangalore
@kushi5439
@kushi5439 5 жыл бұрын
thank you very much ma'am ......very easy way of explanation u had given here.....thanks a lot :) looking many more python videos from you
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
Thank you :)
@Goshbello-Money-AI-Tutorials
@Goshbello-Money-AI-Tutorials 5 жыл бұрын
Thank you again for another well explained tutorial. It’s not just the method you used to solve the problem but I have gained a better understanding with FOR LOOP watching this video. You’re a great teacher. I am waiting for your next video. Thank you
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
Thank you so much :)
@NewIndianera
@NewIndianera 6 жыл бұрын
Mam please make a video on ...Any program how it is executed
@drsmahesan203
@drsmahesan203 3 жыл бұрын
Pythonic way to reverse a string is to use the slice operator E.g. str1 = "Amuls" rev_str = str1[ : : -1] :-)
@moonnyy364
@moonnyy364 4 жыл бұрын
This video helped me so much! Thank you!
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
Pleasure :)
@mohammedmujtabaahmed8337
@mohammedmujtabaahmed8337 3 жыл бұрын
Excellent video. Thanks@!
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Pleasure 😊
@djeraffin
@djeraffin 3 жыл бұрын
Revers number explanation available mam
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Yes 😊
@shreyanshmishra3278
@shreyanshmishra3278 5 жыл бұрын
Superb Explanation!!!
@nikshaygames1074
@nikshaygames1074 3 жыл бұрын
did not work,just found a mistake.
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Give me the program i will check :)
@SB-fs4vi
@SB-fs4vi 3 жыл бұрын
You are really a very good teacher with clear concept. All your videos are helping me a lot as a beginner. Thank you so much🙏🏻
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Glad to hear that :)
@naveenshukla3517
@naveenshukla3517 3 жыл бұрын
Yum Yun😂 But thanks for help
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Pleasure :)
@KK7155.
@KK7155. 3 жыл бұрын
This program we can finish in 1 statement return string[ : : -1]
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Yes but we need to learn different methods to crack interviews :)
@KK7155.
@KK7155. 3 жыл бұрын
@@AmulsAcademy Okk
@aravindersuram6920
@aravindersuram6920 4 жыл бұрын
given a string "aaabbbcc", compress it, = "a3b3c2"
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
def find_duplicate(x): for char in set(x): counts=x.count(char) print(char,counts,end=" ") find_duplicate("aaabbbcc") :)
@aravindersuram6920
@aravindersuram6920 4 жыл бұрын
3a3b3c
@shankarrio2854
@shankarrio2854 4 жыл бұрын
my python 3.8 compiler for 32 bit does not works
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
What is the problem? Getting any error ?
@shankarrio2854
@shankarrio2854 4 жыл бұрын
yaw i got Idle subprocess did not make connection error
@MrDipankar2009
@MrDipankar2009 2 жыл бұрын
Lengthy process...can be done using String slicing...str[::-1]
@shahsikalagowda183
@shahsikalagowda183 11 ай бұрын
Too good mam🤍...ur voice next level🙌🏻😇.. understood clearly 😍🥰
@balakrishnavaidyanathan8572
@balakrishnavaidyanathan8572 3 жыл бұрын
How to do python programming without using library
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Which library ?
@balakrishnavaidyanathan8572
@balakrishnavaidyanathan8572 3 жыл бұрын
I mean in built function
@abuawaish7
@abuawaish7 3 жыл бұрын
Great explanation mam👍❤️
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you :)
@rexrajan5232
@rexrajan5232 10 ай бұрын
I think there is not necessary to include function def, For loop is enough to reverse the string. So what's your opinion?
@saurav031
@saurav031 6 жыл бұрын
can you please add an example of how to reverse words of a given string using for loop. for example given string is "amuls academy of python" and i want the result string as "python of academy amuls". there are many ways to do this using split() and join() method but I want to do this using for loop. Please add a video on this. Thanks
@AmulsAcademy
@AmulsAcademy 6 жыл бұрын
Try this:) sentence = input("enter the input string:") answer = '' temp = '' for char in sentence: if char != ' ' and char!='.': temp += char elif char=='.': answer = char + temp + ' ' + answer temp = '' else: answer = temp + ' ' + answer temp = '' answer = temp + ' ' + answer print(answer)
@saurav031
@saurav031 6 жыл бұрын
Amuls Academy Thanks for your answer but can you please explain the code or atleast make one video tutorial on this.
@5151sunil
@5151sunil 6 жыл бұрын
Nice explanation.. Thanks..
@AmulsAcademy
@AmulsAcademy 6 жыл бұрын
My Pleasure:)
@vengateshprasath2906
@vengateshprasath2906 6 жыл бұрын
I want a tutorial.... tree using python... Like binary tree, linear tree, search tree,
@AmulsAcademy
@AmulsAcademy 6 жыл бұрын
Ok:)
@tusharkhatri5795
@tusharkhatri5795 2 жыл бұрын
can function name be any keyword here you have written as reverse which i think is reserved word . Pls explain as code is executing
@SSRTECH-wf1ps
@SSRTECH-wf1ps 2 жыл бұрын
More easy way i=(intput("enter a string")) Print( i [::-1])
@abhaysrivastav5664
@abhaysrivastav5664 Жыл бұрын
You constructed the solution in a more complicated way which can be solved with the easy loop system.
@ramchandrakulkarni5917
@ramchandrakulkarni5917 2 жыл бұрын
Great Explaination, I was stucked at working of the for loop. But now it is clear. Thank You.
@sayanmukherjee7726
@sayanmukherjee7726 3 жыл бұрын
A great explained video, very useful for me for better understanding of for loop iteration. Thank you.
@t.gowthamarasu1258
@t.gowthamarasu1258 5 жыл бұрын
Uday I too had a same thought
@The_WarMachine
@The_WarMachine 3 жыл бұрын
Nice 👍👍
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you :)
@subrahmanyam1
@subrahmanyam1 3 жыл бұрын
long process. simply it more in two or 3 word writing string is amul. reverse string. out put luma
@anilmacharla6939
@anilmacharla6939 3 жыл бұрын
A million Thanks!
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Pleasure 😊❤️
@uk0707raptor
@uk0707raptor Жыл бұрын
Mam why u have taken that empty string.😢😢
@manproactive6649
@manproactive6649 3 жыл бұрын
wonderful! how is crystal clear explanation! very helpful for beginners like for me
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you 😊
@venkatkrishnan876
@venkatkrishnan876 3 жыл бұрын
Well explained mam
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you 😊
@anuradhakumari6123
@anuradhakumari6123 5 жыл бұрын
Nice explanation
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
Thank you :)
@emptyFull123
@emptyFull123 5 жыл бұрын
Thankyou : For detailed explanation 😊
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
Pleasure :)
@saikiran307
@saikiran307 3 жыл бұрын
Good Explanation
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you :)
@paramvirsohi5922
@paramvirsohi5922 3 жыл бұрын
wow, waht an explanation. I wish I get this fot interview
@swathiram1116
@swathiram1116 5 жыл бұрын
Hai mam but getting syntax error like unindent does not match any indentation level what to do pls explain
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
I think you placed extra space before that statement.
@psiddamma1022
@psiddamma1022 2 жыл бұрын
Thank you mam for clear explanation
@takerixgaming4170
@takerixgaming4170 Жыл бұрын
Magnetic voice mam🔥🔥🔥
@learngurututorials8837
@learngurututorials8837 5 жыл бұрын
Awesome .. explanation.. i really appreciate you.. 👌👌👌
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
Thank you :)
@Ashutoshalt
@Ashutoshalt 2 жыл бұрын
never print inside a function, that's all
@vijaysahal4556
@vijaysahal4556 4 жыл бұрын
nice 👍👍👍👍👍
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
Thank you :)
@RazaviImran
@RazaviImran 5 жыл бұрын
This video is nice, i saw your 4 videos today. But this is great, nice explanation. If you able to make video in hindi it will great opportunity for hindi people just like me, i am not good in english
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
I will start the Hindi channel soon :)
@phaniinakollu4604
@phaniinakollu4604 4 жыл бұрын
@@AmulsAcademy explain django ecommerce website
@LM-th7dj
@LM-th7dj 4 жыл бұрын
Thank you so much! That was very helpful!
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
My Pleasure :)
@Raja-tt4ll
@Raja-tt4ll 4 жыл бұрын
Thanks a lot
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
Pleasure :)
@Ink_Sack
@Ink_Sack 4 жыл бұрын
Very helpful and easy to understand. Thank you
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
Glad it was helpful!
@arfatbagwan48
@arfatbagwan48 2 жыл бұрын
thank you so much ma'am god bless you !
@LongCASTOR
@LongCASTOR 3 жыл бұрын
def reverse(string): return string[::-1]
@kunalpandya8468
@kunalpandya8468 3 жыл бұрын
Simply we can use [::-1]
@praveentiwari5672
@praveentiwari5672 5 жыл бұрын
thanks for explaining everything clearly .........thanks a lot........
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
My Pleasure :)
@ptpitter
@ptpitter Жыл бұрын
reversed_str = input_str[::-1]
@qasemalharbi38
@qasemalharbi38 4 жыл бұрын
Great 👍 I love it please how can we solve it with recursion
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
Try this: def reverse_string(s): if len(s) == 1: return s else: return reverse_string(s[1:]) + s[0] s = input("enter string:") print("The original string is : ",s) print ("The reversed string is : ",reverse_string(s))
@Tech_Brigadier
@Tech_Brigadier 2 жыл бұрын
Grate Tutorials, But mam when I was learning python functions I was taught not to use print statements in a function or else the user's rights to edit the returned value will end up
@VishalSoni-te7hy
@VishalSoni-te7hy 3 жыл бұрын
def reverse(name): print(len(name)) for i in range(len(name)-1,-1,-1): print(name[i],end="") reverse("Vishal")
@mukundmohare310
@mukundmohare310 2 жыл бұрын
excellent explanation Ma'am keep it up and keep growing.👍👍👍
@smhproductions295
@smhproductions295 6 ай бұрын
Feels super easy after seeing this
@katsukibakugou6216
@katsukibakugou6216 3 жыл бұрын
thank you so much! please make more videos like this its really helping!
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Pleasure 😊
@aakashn9480
@aakashn9480 Жыл бұрын
This program not come the ouput
@mohammadhasan6782
@mohammadhasan6782 3 жыл бұрын
Tnks
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Pleasure 😊
@arpitkesarwani6123
@arpitkesarwani6123 5 жыл бұрын
Nice
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
Thank you :)
@karthikeyans1646
@karthikeyans1646 5 жыл бұрын
Nice
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
Thank you :)
@uzairbinbaber6164
@uzairbinbaber6164 4 жыл бұрын
Good
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
Thank you :)
@mayank_8348
@mayank_8348 2 жыл бұрын
It was a great explanation ma'am
@sureshcement2212
@sureshcement2212 Жыл бұрын
I just love ur videos buddy
@estevaofranca5009
@estevaofranca5009 2 жыл бұрын
Thanks for sharing this!!
@sivapriya3276
@sivapriya3276 3 жыл бұрын
thank you somuch for this wonderful vedio.how to reverse a word using recursion
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you :) You can use string slicing method and write the program :)
@sivapriya3276
@sivapriya3276 3 жыл бұрын
@@AmulsAcademy can you say the program
@davidusharauli2227
@davidusharauli2227 6 жыл бұрын
Thanks for reply. but why would for loop add m before a like m+a and not standard way a+m? this part is main part and your reply did not make it clear. if one puts 'amuls'[::-1] it makes sense to reverse. But why would x = i+var should loop from left to write rather than from right to left?
@AmulsAcademy
@AmulsAcademy 6 жыл бұрын
hey, In the string concatenation, 'a' + 'm' is 'am' 'm' + 'a' is 'ma' for i in string: reversed_string = i +reversed_string here string is amuls, so first i value becomes 'a' so for loop executes for i='a', so , reversed_string = i +reversed_string [ here, = 'a' + "" = 'a' [ i = 'a' [ reversed-string = '"" [ empty string ] Now reversed_string is 'a' so next i value becomes 'm' reversed_string = i +reversed_string = 'm' + 'a' ='ma' so reversed_string is 'ma' now. here we are doing, i+reversed_string so we get string is reversed order, that is 'sluma' if we write, reversed_string + i we will get the same string, that is "amuls" :)
@davidusharauli2227
@davidusharauli2227 6 жыл бұрын
Thanks. I got it now. very nice.
@hksaggu1371
@hksaggu1371 Жыл бұрын
Very good thanku
@muralinaremurali9014
@muralinaremurali9014 Ай бұрын
love your voice
@vidithnarayana2346
@vidithnarayana2346 4 жыл бұрын
Python code to reverse a string without effecting special characters?? Ans please..
@kareemsaheb5438
@kareemsaheb5438 4 жыл бұрын
Good video mam
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
Thank you :)
@amitabhgupta21
@amitabhgupta21 5 жыл бұрын
You are very good and your way is best,keep it up
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
Thank you :)
@ananthvenkatreddygaddam3041
@ananthvenkatreddygaddam3041 6 жыл бұрын
Hi I have written code like this but i am not able to be executing in python 2.x could you please help me def reverse(str): reversed_str="" for i in str: reversed_str= i+reversed_str print("reversed string is:",reversed_str) str=input("enter a string:") print ("entered string",str) reverse(str)
@AmulsAcademy
@AmulsAcademy 6 жыл бұрын
Because you are using python 2, in the output: first a message will display that is, enter a string: here you need to enter string that is, "amuls" [ you need to write your input within the double quotes ] Because In python 3 input() by default treat input as string. But in python 2 input() will evaluate the input. OR you can write code like this: python 2's raw_input is equal to python 3's input() so instead of input() you can use raw_input() def reverse(str): reversed_str="" for i in str: reversed_str= i+reversed_str print "reversed string is:",reversed_str str = raw_input("enter a string:") print "entered string", str reverse(str) here you can enter input without double quotes:)
@ananthvenkatreddygaddam3041
@ananthvenkatreddygaddam3041 6 жыл бұрын
Thank you so much!!!!!!!!!!!
@AmulsAcademy
@AmulsAcademy 6 жыл бұрын
welcome:)
@shuaibbenhamouda548
@shuaibbenhamouda548 3 жыл бұрын
fockin earape omg
@NasirsCodeStudio
@NasirsCodeStudio 5 жыл бұрын
Thanku.... Very helpful
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
Pleasure :)
@craftnclash1952
@craftnclash1952 4 жыл бұрын
confused too much
@manuchowdary7848
@manuchowdary7848 4 жыл бұрын
good explanation
@ajinkyarajurkar7457
@ajinkyarajurkar7457 6 жыл бұрын
can u upload a video on "reverse" which is used everywhere in python like list and reverse operation on some other.. . . like reversing a list kind of
@AmulsAcademy
@AmulsAcademy 6 жыл бұрын
Are you asking about the list.reverse method?
Palindromic Prime Numbers in Python Programming
10:33
Amulya's Academy
Рет қаралды 23 М.
Solve any Star Pattern program in Python
18:44
Simply Coding
Рет қаралды 967 М.
Cute
00:16
Oyuncak Avı
Рет қаралды 12 МЛН
Новый уровень твоей сосиски
00:33
Кушать Хочу
Рет қаралды 5 МЛН
Как подписать? 😂 #shorts
00:10
Денис Кукояка
Рет қаралды 8 МЛН
РОДИТЕЛИ НА ШКОЛЬНОМ ПРАЗДНИКЕ
01:00
SIDELNIKOVVV
Рет қаралды 2,3 МЛН
Python Decorators in 15 Minutes
15:14
Kite
Рет қаралды 444 М.
Pydantic Tutorial • Solving Python's Biggest Problem
11:07
pixegami
Рет қаралды 275 М.
Python Programs - Factorial Program Using Recursion
18:08
Amulya's Academy
Рет қаралды 74 М.
Python Programs - Factorial Program Using for loop
10:30
Amulya's Academy
Рет қаралды 143 М.
Functions in Python are easy 📞
10:38
Bro Code
Рет қаралды 495 М.
Python Program For Matrix Addition and Subtraction
13:58
Amulya's Academy
Рет қаралды 76 М.
6 Tips to write BETTER For Loops in Python
9:19
Patrick Loeber
Рет қаралды 249 М.
Cute
00:16
Oyuncak Avı
Рет қаралды 12 МЛН