Telusko = 1 Navin_Reddy_Sir = 100 try: print("Telusko + Navin_Reddy_Sir") except: print("you don't have any errors, Sir.") finally: print("you are still the best")
Sir your teaching style is innovative and the tidbits that you say in-between is what makes you a great teacher. I've been taught by many teachers and I can say the level at which teach, for which other teachers get paid a lot, but you deliver all this for free is commendable. Thank you very much Sir for rejuvenating my passion for Python.
I thought the same but it does look tidier to the eye... as a logical block of code before embarking on some other idea... kind of like paragraphs in writing prose...
If you do not have the finally clause and you get an error the file won't close. Finally ensures that regardless of the errors taking place in the program , it would perform the task mentioned.
@@aryanfalke5751 i think that u had failed to understand the question correctly. he is asking that what is the need of finally, if we just simply put the 'resource closed' statement outside all the blocks of try and except.
Let just say in your except block you mentioned only 1 type of error ( Value error) and when you run the code you divided any number with 0 In that case the "resource close" statement not going to run Finally: ensure that every last block of code execute even if there are multiple errors
*See if you write 'resource closed' outside then it will get printed only when there is not an error because the execution stops when there is an error previously*
Hey Telusko, got an incorrect output please check it: It is not asking for input in following case: a=5 b=0 try: print("Resource opened") print(a/b) k=int(input("Enter a number :")) print(K) except ZeroDivisionError as e: print("Hey, error and cause of error is :",e) except ValueError as e: print("Hey, Invalid Input :",e)
except Exception as e: print("Hey Something went wrong :",e)
finally: print("resource closed") output: Resource opened Hey, error and cause of error is : division by zero resource closed Question is here why it is not asking me to enter a number K ?
a=5 b=2 try: print("resource open") print(a/b) k=int(input("enter a number")) print(k) except ZeroDivisionError as e: print("Hey, you cannot divide a number by zero",e) except ValueError as e: print("Invalid input", e) except Exception as e: print('something went wrong...',e) finally: print('resource closed')
Sir...thank you for your python beginners tutorials...sir are you going to upload videos on python frameworks and advanced libraries... Like sckit learn numpy opencv etc..? please let me know sir...
explanation is exceptional/awesome but only complain is about the cuts in the video which strains eyes...please try to minimize the cuts. everything else is phenomenal.
So I am slowly approaching the end of your Python course, Sir, and I have to thank you. I have started just a few weeks ago as a total beginner, and because of you, I can now write a simple applications, and (and that's most important) I can think as a programmer which made learning other languages a lot easier for me. Thank you, Sir Navin Reddy
Great explanation. Also I like all your catch phrases. Eg, "Hold on" and "For those with Java, C++ background will be familiar with this" and "You might be wondering" and "What would happen if" and "Oh thats weird, what if i do this.."
What if you want to continue prompting the user until they enter valid input? I can't get the loop right, it will except the error once if they enter a character instead of an integer, then it will prompt the user for valid input but if they enter a character again it won't handle the exception again and stops my execution.
Hi Navin, As you mentioned, if we want some piece of code irrespective of whether an exception was caught or not, then, we use finally block. So, wanted to ask, what if we don't use finally block and instead write that piece of code post our except block. Then too, our piece of code will execute whether or not an exception was caught or not. Will there be a difference? if yes, what's the benefit of using finally block instead of writing that code after except block? Example with finally block: a = 5 b = 0 try: print("DB connection started") print(a/b) except Exception as e: print("Exception caught !!", e) finally: print("DB connection closed")
The same example without finally block: a = 5 b = 2 try: print("DB connection started") print(a/b) except Exception as e: print("Exception caught !!", e) print("DB connection closed")
Since you have given the Exception keyword, it will handle all the exceptions. Try this: a = 5 b = 0 try: print("DB connection started") print(a/b) except ValueError as e: print("Exception caught !!", e) print("DB connection closed") In the above case the print("DB connection closed") statement would never run. but now try this and the print("DB connection closed") always runs even if any error occurs. a = 5 b = 0 try: print("DB connection started") print(a/b) except ValueError as e: print("Exception caught !!", e) finally: print("DB connection closed") Hopefully it made sense now
Will this work instead of finally?? Try: print("resource open") print(a/b) except Exception as e: print("Hey, you cannot divide by 0", e) print("resource closed")
Sir you are great with thier easy explanation.i learn most of the thing in python for your channel .it is very good and easy to understand. Thank you sir...
A good class that can easily confuse if one is not careful.....otherwise you are Mr Good in this field, as a starter, I feel challenged to when I will be there. Again thanks to my classmates because the comments we write here are also resourceful by far when I read, understand and run them, I get informed of extra things. Big up guys.
I think finally is a useless function, instead of finally without indentation if we put print then also at any cost it will print so what is the use of finally.
No that's not the case. Suppose you have else and finally clauses. Now suppose something wrong (error) happens in Else which generates an exception, the program will terminate. But if we have finally block, interpreter will first execute finally block and then will generate the exception. Its not possible without finally block. Secondly, in user defined function, finally can have a different behavior. Watch my video discussing this in detail.
Am I the only one that actually opens the fridge and leaves it open 😂 just looking at the food lol. You’re the best bro you explain so well I love your videos
Thanks and appreciate you Sir for ur effort. I have the same question which Abhi asked. Will you upload videos on NumPy, pandas and other libraries. How much python knowledge we should require to get started with a job in python? Do we require knowledge of all libraries and framework like Django, pylons? To start a job in python what we skillset do we actually require in python. Please guide SIR..Thanks a lot
Navin Sir I am just a 15-year-old kid interested in programming. In school, we are taught JAVA language. I know the basics but still, you teach so well that in my 10th grade currently sitting at home during the lockdown I stay awake until 11:00 pm after completing the studies just because u teach with so many interesting real-life examples. So just love the way u teach. I have watched 63 videos in 8 days. I am really enjoying. Thank u!!!!!!!!
@Aanshumaan Shrijai VII C Roll No. 37 Thats Good!! I was told one thing you know by one of my connections on LinkedIn just to motivate you here is the thing: Udit Rathod You should explore never stop exploring ... just keep in mind you have to be Dora the explorer because that's what I do. That's the man UDIT RATHOD who told me pretty inspiring things!! If possible connect with me on LinkedIn we can discuss a lot of things!! You can also get ideas from me we can exchange challenges lot more.
Interesting that k is accepted even though it appears to be an undefined variable Modified your code to accept inputs a and b: a = 0 b = 0 try: print("Resource open: ") a = int(input("Enter a numerator: ")) b = int(input("Enter a denominator: ")) print(a/b) # k = int(input("Enter a number: ")) #print (k) except ZeroDivisionError as e: print("You cannot divide by zero", e) except ValueError as e: print("Invalid input") except Exception as e: print("Something went wrong") finally: print("Resource closed")
(Siddesh): Use of "finally" is not clear..... Even without using "finally" if we just printed "resource closed" post "exception" block if will still work,,,, What's the significance of using the feature "finally"...Doesn't make sense to me yet Navin.. Can you please help clarify,... Note: I could see similar questions posted but didnt have a clear explaination yet
00:08 Types of Errors in Python 02:07 Runtime errors occur during execution and can be caused by user input, missing files, or network issues. 04:01 Even if you get an exception or error, the execution should not stop. 05:52 To solve the problems of user comprehension and execution stopping, use a try-except block in Python. 07:52 Exception handling allows us to handle errors and execute alternate code when an error occurs 09:41 Always ensure to close a resource that you open in a try block. 11:35 Exception handling in Python allows execution of code, whether an exception occurs or not. 13:39 Exception Handling in Python 15:35 Exception Handling in Python with try, except, and finally blocks Crafted by Merlin AI.
Sir i have a doubt: a = 3 b = 0 If b != 0: print(a / b) else: print("can't enter zero in b) Sir, if this problem solved by if else, then i should we use Try-expcept. Please help i want to understand exception handling
how to handle mutiple exception like if we have divide by zero error and also Value error at same time..this code is just jumping out of try block for the first exception and not detecting second one...tried with break/break_continue..but not getting expected output
Sir inside try if we have 2 statements with 2 errors, when we execute them just after the first error it is getting out to that exception handling and printing that but it is leaving the 2nd error inside the try. So if we want it too to be handle should I write it in another try statement or any other method available ? [ try: print(5/0) print(int('p')) consider indentations]
what if two errors are to be executed at once, for say in the above example if we use b=0 and give "p" as input. Only one error is executed(it jumps out ). How to make all execution at once. Please answer my question
Navin your videos are amazing. Navin, please specify else block as well. i.e, try block for checking any error, except block will handle the error, else block will execute if there is no error, and finally block will excecute regardless the result of try and except block.
will only one except block run if we got an error? Consider if we have a general exception(Exception as e) and a specified exception(say., ValueError)......
what is the difference between raise and return exception? If there are multiple exceptions we don't know, can all be handled in the same except Exception as e? How to handle errors from multiple processes in multiprocessing in Python?
Hi. I've been trying to insert an input statement but everytime i try to put a character, the code is just running. As if i havent put a character. No error, no nothing. Just the statement in quotes Help anyone?
love the way you teach. Ah just had a little request may be you should have used "You may loose crores of rupees" instead of using "You may loose billions of dollars".
Mr Perfect = Navin Reddy Sir
Python=Navin reddy sir💕
"The general doctor" 👍
Nicely put. My compliments!
Itna to college wale bhi nahi karate jitna navin ji samjha dete h ❣️❣️❣️
Telusko = 1
Navin_Reddy_Sir = 100
try:
print("Telusko + Navin_Reddy_Sir")
except:
print("you don't have any errors, Sir.")
finally:
print("you are still the best")
High IQ comment
I literally learned the entire python language through your videos. Tysm for great videos and simplified explanation
@@etcetc3800 what r u doing here ....! Then
Bullshit
@@etcetc3800 bruh
mamulu racha kadu, I was almost ready to pay for python classes and i found this channel. THE BEST channel to learn coding.
Sir your teaching style is innovative and the tidbits that you say in-between is what makes you a great teacher.
I've been taught by many teachers and I can say the level at which teach, for which other teachers get paid a lot, but you deliver all this for free is commendable.
Thank you very much Sir for rejuvenating my passion for Python.
i was struglling with this topic from long time. u made it just like clear water. thank u
This is how you teach. keep it basic/simple. Thanks, great job.
Amazing Teaching skill. God bless you sir.
Thanks a lot Sir!
thank you for this lesson, well digested
Excellent explanation. You are an extraordinary teacher🙏
Pretty clear explanation; thanks for sharing your knowledge.
what is the need of finally: if we can just print('resource closed") outside will that make sense?
I thought the same but it does look tidier to the eye... as a logical block of code before embarking on some other idea... kind of like paragraphs in writing prose...
If you do not have the finally clause and you get an error the file won't close. Finally ensures that regardless of the errors taking place in the program , it would perform the task mentioned.
@@aryanfalke5751 i think that u had failed to understand the question correctly. he is asking that what is the need of finally, if we just simply put the 'resource closed' statement outside all the blocks of try and except.
Let just say in your except block you mentioned only 1 type of error ( Value error) and when you run the code you divided any number with 0
In that case the "resource close" statement not going to run
Finally: ensure that every last block of code execute even if there are multiple errors
*See if you write 'resource closed' outside then it will get printed only when there is not an error because the execution stops when there is an error previously*
Hey Telusko, got an incorrect output please check it:
It is not asking for input in following case:
a=5
b=0
try:
print("Resource opened")
print(a/b)
k=int(input("Enter a number :"))
print(K)
except ZeroDivisionError as e:
print("Hey, error and cause of error is :",e)
except ValueError as e:
print("Hey, Invalid Input :",e)
except Exception as e:
print("Hey Something went wrong :",e)
finally:
print("resource closed")
output:
Resource opened
Hey, error and cause of error is : division by zero
resource closed
Question is here why it is not asking me to enter a number K ?
Simplification in learning program called Telusko 💥
fantastic explanation.
Thanks a lot for such a great explantion!
a=5
b=2
try:
print("resource open")
print(a/b)
k=int(input("enter a number"))
print(k)
except ZeroDivisionError as e:
print("Hey, you cannot divide a number by zero",e)
except ValueError as e:
print("Invalid input", e)
except Exception as e:
print('something went wrong...',e)
finally:
print('resource closed')
Wow. A big thumbs up for this video. Made my day.
Thank you.
Sir...thank you for your python beginners tutorials...sir are you going to upload videos on python frameworks and advanced libraries... Like sckit learn numpy opencv etc..? please let me know sir...
Best python teaching.. Love the way of teaching...🖤🖤
great sir got 100% there...thnks
best and short explanation!!
sir you are superb
marvelous bro keep it up👍
explanation is exceptional/awesome but only complain is about the cuts in the video which strains eyes...please try to minimize the cuts. everything else is phenomenal.
Amazing work there, will you be making tutorials of creating GUI in python?
Can we execute 2 except blocks ?
It was always confusing for me about the error handling. You made it crystal clear today. I like your simplicity in teaching complex concepts.
So I am slowly approaching the end of your Python course, Sir, and I have to thank you. I have started just a few weeks ago as a total beginner, and because of you, I can now write a simple applications, and (and that's most important) I can think as a programmer which made learning other languages a lot easier for me. Thank you, Sir Navin Reddy
Good tut
Great explanation.
Also I like all your catch phrases. Eg, "Hold on" and "For those with Java, C++ background will be familiar with this" and "You might be wondering" and "What would happen if" and "Oh thats weird, what if i do this.."
What if you want to continue prompting the user until they enter valid input? I can't get the loop right, it will except the error once if they enter a character instead of an integer, then it will prompt the user for valid input but if they enter a character again it won't handle the exception again and stops my execution.
Hi Navin,
As you mentioned, if we want some piece of code irrespective of whether an exception was caught or not, then, we use finally block.
So, wanted to ask, what if we don't use finally block and instead write that piece of code post our except block. Then too, our piece of code will execute whether or not an exception was caught or not.
Will there be a difference? if yes, what's the benefit of using finally block instead of writing that code after except block?
Example with finally block:
a = 5
b = 0
try:
print("DB connection started")
print(a/b)
except Exception as e:
print("Exception caught !!", e)
finally:
print("DB connection closed")
The same example without finally block:
a = 5
b = 2
try:
print("DB connection started")
print(a/b)
except Exception as e:
print("Exception caught !!", e)
print("DB connection closed")
Since you have given the Exception keyword, it will handle all the exceptions. Try this:
a = 5
b = 0
try:
print("DB connection started")
print(a/b)
except ValueError as e:
print("Exception caught !!", e)
print("DB connection closed")
In the above case the print("DB connection closed") statement would never run. but now try this and the print("DB connection closed") always runs even if any error occurs.
a = 5
b = 0
try:
print("DB connection started")
print(a/b)
except ValueError as e:
print("Exception caught !!", e)
finally:
print("DB connection closed")
Hopefully it made sense now
@@vjnimbalkar thanks Vijay. It helped.
Thank you very much for this tutorial! It was that part of coding what I have never understood exactly, until I've seen your video!
He is genius thank you so much
Thank you so much sir 😊. It's very helpful for me
Sir, I got one doubt. If we want two exceptions at a time how can we do it?
Nice videos Navin sir
These are very helpful to me. Thank you a lot for your hard work.
You're a great instructor, thanks for sharing these concepts in a way that beginners can actually understand :)
i wish i had a teacher like u in my school!!!!!!!!!!!!
Will this work instead of finally??
Try:
print("resource open")
print(a/b)
except Exception as e:
print("Hey, you cannot divide by 0", e)
print("resource closed")
Sir you are great with thier easy explanation.i learn most of the thing in python for your channel .it is very good and easy to understand.
Thank you sir...
When you were talking about different doctors in examples, I yelled, ''DENTIST DOCTOR!".
xD
Hello Sir your way of teaching and the presentation is amazing 👍👍
u made easier sir better than my teachers or frnds thanks a lot
Navin sir :- God of Programming for me.....Helped me get through interview and many concept 😘
what would be the use of finally if anything under will be executed anyway?
*Best video in this topic*
Thank You Sir
a question arises how ur process finished with exit code 1 instead of 0...at the bottom of the code or page
I have started loving python because of your teaching sir hats off to you🙏🙏🙏🙏🙏
A good class that can easily confuse if one is not careful.....otherwise you are Mr Good in this field, as a starter, I feel challenged to when I will be there. Again thanks to my classmates because the comments we write here are also resourceful by far when I read, understand and
run them, I get informed of extra things. Big up guys.
I think finally is a useless function, instead of finally without indentation if we put print then also at any cost it will print so what is the use of finally.
No that's not the case. Suppose you have else and finally clauses. Now suppose something wrong (error) happens in Else which generates an exception, the program will terminate. But if we have finally block, interpreter will first execute finally block and then will generate the exception. Its not possible without finally block.
Secondly, in user defined function, finally can have a different behavior.
Watch my video discussing this in detail.
do freeze the background animation, video file size will be less than half
print ("Beauty Right!")
Awesome
A good teacher doesn't need a whole day for any good concept simply this much time is enough
Thank you sir 👍
thank you so much, i was able to figure out my hw because of this video
navin sir thopu velithe appu...........
easy... this have in js.
Can I like this a million times? Thank you Telusko!
Great teaching style sir all doubts are clear👌👌👍👍👍👍🎂
Can 2 except run at a same time ?
Am I the only one that actually opens the fridge and leaves it open 😂 just looking at the food lol. You’re the best bro you explain so well I love your videos
Any1 on last minute preparation
Thanks and appreciate you Sir for ur effort. I have the same question which Abhi asked. Will you upload videos on NumPy, pandas and other libraries. How much python knowledge we should require to get started with a job in python? Do we require knowledge of all libraries and framework like Django, pylons? To start a job in python what we skillset do we actually require in python. Please guide SIR..Thanks a lot
Can we use try multiple times
Nice explanation sir.... Thank u so much🤗
What if have an error in division as well as in the taking input from the user will it show both the error at the same time
Plz Reply.
Ys is also got the same doubt but when I gave b=0 i didn't get "number given in input as output" I got zerodivison error only ...
U should go the doctor skin, your head skin is green. Try to fix that man! Make a double render...
Thank you so much man! You just saved my weekend!
Learned something you ask?...dude literally taught me what I couldn't understand in 3 lectures in my class..
Also finally doesn't give a fuc-
The introduction of finally was just like a climax in movie 😁
The best video for Exception handling in UA-cam. Nailed it sir.
Navin Sir I am just a 15-year-old kid interested in programming. In school, we are taught JAVA language. I know the basics but still, you teach so well that in my 10th grade currently sitting at home during the lockdown I stay awake until 11:00 pm after completing the studies just because u teach with so many interesting real-life examples. So just love the way u teach. I have watched 63 videos in 8 days. I am really enjoying. Thank u!!!!!!!!
@Aanshumaan Shrijai VII C Roll No. 37 Thats Good!! I was told one thing you know by one of my connections on LinkedIn just to motivate you here is the thing:
Udit Rathod
You should explore never stop exploring ... just keep in mind you have to be Dora the explorer because that's what I do.
That's the man UDIT RATHOD who told me pretty inspiring things!! If possible connect with me on LinkedIn we can discuss a lot of things!! You can also get ideas from me we can exchange challenges lot more.
@Aanshumaan Shrijai VII C Roll No. 37 Then how can we be in contact?
Sir there is one more method: with statement
Interesting that k is accepted even though it appears to be an undefined variable
Modified your code to accept inputs a and b:
a = 0
b = 0
try:
print("Resource open: ")
a = int(input("Enter a numerator: "))
b = int(input("Enter a denominator: "))
print(a/b)
# k = int(input("Enter a number: "))
#print (k)
except ZeroDivisionError as e:
print("You cannot divide by zero", e)
except ValueError as e:
print("Invalid input")
except Exception as e:
print("Something went wrong")
finally:
print("Resource closed")
తెలుగు :-థన్యవాదములు
I understand this topic only by ur video, thanks a lot
(Siddesh): Use of "finally" is not clear..... Even without using "finally" if we just printed "resource closed" post "exception" block if will still work,,,, What's the significance of using the feature "finally"...Doesn't make sense to me yet Navin.. Can you please help clarify,...
Note: I could see similar questions posted but didnt have a clear explaination yet
I wish I could give some more likes to sir's lectures
Sir 🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻The way you are teaching 👌🏼👌🏼👌🏼👌🏼NAA buthoo na bavishyath🤝🤝🤝🤝✊✊
00:08 Types of Errors in Python
02:07 Runtime errors occur during execution and can be caused by user input, missing files, or network issues.
04:01 Even if you get an exception or error, the execution should not stop.
05:52 To solve the problems of user comprehension and execution stopping, use a try-except block in Python.
07:52 Exception handling allows us to handle errors and execute alternate code when an error occurs
09:41 Always ensure to close a resource that you open in a try block.
11:35 Exception handling in Python allows execution of code, whether an exception occurs or not.
13:39 Exception Handling in Python
15:35 Exception Handling in Python with try, except, and finally blocks
Crafted by Merlin AI.
Sir i have a doubt:
a = 3
b = 0
If b != 0:
print(a / b)
else:
print("can't enter zero in b)
Sir, if this problem solved by if else, then i should we use Try-expcept. Please help i want to understand exception handling
Very clear explanation Sir...Thanks a Lotttttttttttttttttttt Sir
You really have a knack for teaching ...brilliant
how to handle mutiple exception like if we have divide by zero error and also Value error at same time..this code is just jumping out of try block for the first exception and not detecting second one...tried with break/break_continue..but not getting expected output
Sir inside try if we have 2 statements with 2 errors, when we execute them just after the first error it is getting out to that exception handling and printing that but it is leaving the 2nd error inside the try. So if we want it too to be handle should I write it in another try statement or any other method available ? [ try:
print(5/0)
print(int('p')) consider indentations]
what if two errors are to be executed at once, for say in the above example if we use b=0 and give "p" as input. Only one error is executed(it jumps out ). How to make all execution at once. Please answer my question
Navin your videos are amazing.
Navin, please specify else block as well. i.e, try block for checking any error, except block will handle the error, else block will execute if there is no error, and finally block will excecute regardless the result of try and except block.
Can we use if else statement instead of using except statement again and again . I think it will work for perfectly
will only one except block run if we got an error? Consider if we have a general exception(Exception as e) and a specified exception(say., ValueError)......
Tqq so much sir. You nailed it.i didn't understood this concept java but you made it clear in Python
what is the difference between raise and return exception? If there are multiple exceptions we don't know, can all be handled in the same except Exception as e? How to handle errors from multiple processes in multiprocessing in Python?
Rule # X of Programming: Never assume the user will not do something stupid. If you have goofed around in video games you know why.
Hi. I've been trying to insert an input statement but everytime i try to put a character, the code is just running. As if i havent put a character. No error, no nothing. Just the statement in quotes
Help anyone?
accept vs except: syntax error
love the way you teach. Ah just had a little request may be you should have used "You may loose crores of rupees" instead of using "You may loose billions of dollars".