• Register
1 vote
19 views

Problem:

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

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 21 views
21 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 40 views
40 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 16 views
16 views
Problem : You may have an infinite update loop in a component render function.
asked Feb 12 Shovo210 2.5k points
0 votes
1 answer 649 views
649 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
1 vote
1 answer 827 views
827 views
Problem: I am new in python programming and I have been doing a course on it as a new comer I tried to repeat some char in a string. I wrote a code : def Work(str): for i in range(len(str)): return i * 2 But it does not work . how can I do this?
asked Apr 3, 2020 LizzyM 6.1k points
1 vote
1 answer 750 views
750 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
0 votes
1 answer 12 views
12 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 5.8k points
0 votes
1 answer 13 views
13 views
Problem: How many except statements can a try-except block have? Explanation: There has to be at least one except statement. 2.In the try clause, all statements are executed until an exception is encountered. except is used to catch and handle the exception(s) ... encountered in the try clause. else lets you code sections that should run only when no exceptions are encountered in the try clause.
asked Jan 26 Mashhoodch 9.1k points
0 votes
1 answer 2.5K views
2.5K views
Problem : MySample.csv contains the below details : NAME Id No Dept Tommy 1 12 CS Jimmy 2 35 EC Bonny 3 21 IT Franky 4 61 EE And my Python file contains the below code : import csv myifile = open('mysample.csv', "rb") read = csv.reader(myifile) for row in read : ... in for row in read : _csv.Error: iterator should return strings, not bytes (did you open the file in text mode?) How should I fix it?
asked Jan 2, 2020 alecxe 7.5k points
0 votes
1 answer 198 views
198 views
Problem : In Python, code blocks are defined by the tabs, not by the ";" at the end of the line if number > 10 and number < 25: print "1" Is mutliple lines possible in python? like... if number > 10 and number < 25: print "1"
asked Oct 21, 2019 peterlaw 6.9k points