• Register
1 vote


I am a beginner in programming language and I hvae been doing some coding practice and learning some programing logics .So, can anyone explain me the return statement in a void method of python?

10 7 2
6,060 points

Please log in or register to answer this question.

1 Answer

1 vote
Best answer


Any method declared void doesn't return a value. In such a case, a return statement can be used to branch out of a control flow block and exit the method and is simply used like this: return; If you try to return a value from a method that is declared void , you will get a compiler error

In python, return statements allow us to come out of a function and also return a value back to the caller of the function. They cause a function to stop its execution and hand over the value to whichever other statement called it. Even if you were to write any code after a return statement, it would not get executed, because the control would break out of the function. And return statements help in getting information back from a function. But why would you need information back from a function? This is because, while coding an actual application, you would be able to exchange the returned values back and forth between different parts of your programs.

Hope I am able to explain this to you, if you are still confused ask me any thing you want to know.

11 6 4
34,950 points

Related questions

1 vote
1 answer 51 views
Problem: I admit it that Java programming is fun but it seems confusing sometimes. I am trying to adopt somethings about method and object in java. I know how to create a method and calling it inside the main method. I have a very simple question, can a void ... have a return statement? What happens if I try to return values from a void method? A well-explanation is expected. Thanks again, guys.
asked Mar 30, 2020 Gavin 15.3k points
1 vote
1 answer 45 views
Problem: I am exploring the c++ programming language nowadays. It’s really interesting to learn new things every day. I was trying to adopt the methods in c++ but struggling to return values from a void method. I actually want to know that if it is ... a return statement in a void method. Thanks for your co-operation in this learning process. I really appreciate your effort. Thanks again.
asked Mar 25, 2020 Gavin 15.3k points
0 votes
1 answer 5 views
Problem: Hi, any idea that what should I do to fix .. you may have a return statement in a void method.
asked Apr 3 Ifra 37.2k points
0 votes
1 answer 15 views
Problem: Please solve it … Because I am unable to find out the solution... you must have a return statement in a non-void method.
asked Mar 23 Ifra 37.2k points
0 votes
1 answer 5 views
Problem: What if I write return statement in constructor? Is it standard conformant? struct A { A() { return; } }; The above code compiles fine, without any error at ideone. But the following code doesn't: struct A { A() { return 100; } }; It gives ... forbids the second one? Is there any explicit statement? Is the return type in the first example void? Is there any implicit return type at all?
asked Apr 24 Humaira ahmed 50.7k points
0 votes
1 answer 5 views
Problem: Please let me know about the difference between void method and return value method .
asked Apr 30 salim1 60.6k points
0 votes
1 answer 797 views
Problem : I am trying to learn Java, I am very newbie however I wanted to know what I do to get the "run" it. I am facing below error: Static Error: This class does not have a static void main method accepting String[]. Below is my code: public class MyCaneirinho { public static void mycontar ... { System.out.println(j + x + y); } else { System.out.println(j + x + y + z); } } } } // MyCarneirinho
asked Dec 10, 2019 alecxe 7.5k points
0 votes
1 answer 21 views
Problem: Hello there! I am working with C# in Visual Studio and I am learning user-defined functions in C#. When I try to execute my program, it throws an error that says method must have a return type. I have checked my function and I find nothing wrong with it. ... ;t know what’s the problem and what should I do. If someone could tell me, that would be a big favor. Thanks in advance
asked Oct 16, 2020 Code Learner 9.9k points
0 votes
1 answer 3 views
Problem: Can anyone tell me what could be the return when the count method applied on a list?
asked Apr 10 zayed1 61.8k points
1 vote
1 answer 1K views
Problem: Hello Pal, I have a query regarding the python programming language. The question is, which method will return an empty string when it has attempted to read beyond the end of a file? Do you have any idea about this? Thanks
asked Mar 16, 2020 Gavin 15.3k points