PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 30


If you need a function that does nothing, what would you use instead of XXX? (Choose two.)

Show Answer
Correct Answer: AB

To create a function in Python that does nothing, you can use 'pass' and 'return'. The 'pass' statement is specifically designed to do nothing and is often used as a placeholder for future code. The 'return' statement with no value also causes the function to do nothing by returning None implicitly. While 'None' can represent the absence of a value, placing it in the body of a function would be interpreted as a literal value and not as a functional placeholder. Hence, the correct choices are 'pass' and 'return'.

Discussion

16 comments
Sign in to comment
BackyOptions: AB
Feb 19, 2022

Answer should be AB D would work but any constant like None, True, False, 3, 5.333 would work but this is not specific to a function, you could place them at the shell prompt and it would work the same D should not be even on the list when B is included, B takes the precedence over D

rocky48
Mar 11, 2022

A. pass - Will do nothing B. return - Will return nothing C. exit - Will exit the program D. None - "None" refers exactly to the intended functionality - it is nothing, and has no behaviour. A & D seem to be fine.

Backy
Apr 7, 2022

I think you do not have a clue about basics of programming. If you put just 'None' on the line it will be translated into 'None' followed by 'return' anyway. Any function will always have 'return' at the end, it is implied. So by definition, if a function has only 'return' then it does nothing because 'return' is always added anyway and it is redundant. Most importantly, the actual exam would never include a question with such overlapping answers

AdeshinaOptions: AD
Dec 12, 2022

A. pass D. None The pass and None keywords can be used to define a function that does nothing. The pass keyword can be used as a placeholder for code that has not yet been implemented, or as a way to create an empty block of code. The None keyword represents the null value and can be used to indicate that a function does not return a value. In the case of the idler function, using either pass or None as the body of the function will cause the function to do nothing when it is called.

MallieOptions: AB
Dec 13, 2022

Pass & Return are the preferred solutions used on the Edube course A & B

EltonAugustonOptions: AD
Jun 4, 2023

but using return suggests that the function is intended to produce a result, even if it is not explicitly defined. so its AnD

macxszOptions: AD
May 3, 2022

A. pass D. None

smarty_arse
Jan 21, 2022

Correct answers

rocky48Options: AD
Mar 8, 2022

Options : A,B,C & D will all return the same empty result on the console prompt. But None is over-writing the output and exit will exit the function, thus i would go with A & D.

rocky48
Mar 11, 2022

A. pass - Will do nothing B. return - Will return nothing C. exit - Will exit the program D. None - "None" refers exactly to the intended functionality - it is nothing, and has no behaviour.

666_mOptions: AD
May 6, 2022

A&D is correct

PremJaguarOptions: AB
Jul 19, 2022

should be AB because return is automatic and pass does nothing

agus007Options: AB
Nov 4, 2022

The answer should be AB, pass does nothing. return is always implicit, so make it explicit will do the same, nothing.

ryanzouOptions: AB
Mar 8, 2023

AB are correct

wedliveOptions: AB
May 2, 2023

AB You can use the pass keyword to create a function that does nothing and just returns control to the caller, or you can use the return statement without any value to exit the function and return None. The exit function is used to terminate the program, not to create a function that does nothing.

Acid_ScorpionOptions: AB
Oct 2, 2023

A & B is correct

TheFivePipsOptions: AD
Dec 6, 2023

This is a dumb question. return, pass, and None will all work. It kinda just depends on how you want to do it. pass is probably to best to use, since it pretty clearly indicates youre just moving on. return will implicitly return None, and so will None. I guess Id give the edge to None over return just because its slightly more clear but its a function that does nothing, who cares?

OracleistOptions: AD
Feb 6, 2024

I think A,D return will have the same effect of None, but return will made a return to a function call, that is different then do nothing as the question ask.

G3n
Jun 18, 2024

The answers in the dumps are good to remember! The bulk of the exam questions are from these exam dumps. The questions with mistakes in them or missing : etc are in the exam but in the correct answer form, do remember the correct answers as well as the answers with the mistakes in the coding. There are a few questions that are slightly different but you can find the answers from the previous or next question/answers! Hope this helps!