Python Institute PCAP Exam Practice Questions (P. 5)
- Full Access (141 questions)
- Six months of Premium Access
- Access to one million comments
- Seamless ChatGPT Integration
- Ability to download PDF files
- Anki Flashcard files for revision
- No Captcha & No AdSense
- Advanced Exam Configuration
Question #21
Can a module run like regular code?
- Ayes, and it can differentiate its behavior between the regular launch and importMost Voted
- Bit depends on the Python version
- Cyes, but in cannot differentiate its behavior between the regular launch and import
- Dno, it is not possible; a module can be imported, not run
Correct Answer:
A
A

Absolutely, a module in Python can be run just like any regular script. More interestingly, it can behave differently depending on whether it is being executed directly or imported into another script. This is managed by using the __name__ variable. If the module is the main program being executed, the __name__ variable will be set to "__main__". This allows developers to design modules that double as reusable components or standalone programs, by checking the state of __name__ before executing specific blocks of code. This flexibility is a powerful feature for writing adaptable and modular Python code.
send
light_mode
delete
Question #22
Select the valid fun () invocations:
(Choose two.)

(Choose two.)

send
light_mode
delete
Question #23
A file name like this one below says that:
(Choose three.)
services, cpython 36.pyc
(Choose three.)
services, cpython 36.pyc
- Athe interpreter used to generate the file is version 3.6Most Voted
- Bit has been produced by CPythonMost Voted
- Cit is the 36 version of the file
- Dthe file comes from the services.py source fileMost Voted
Correct Answer:
ABD
ABD

In the filename "services, cpython 36.pyc," the segment 'cpython 36' clearly indicates that the file was compiled by CPython version 3.6. Additionally, the 'services' before any comma in the filename strongly suggests its origin from a source file named 'services.py'. This naming schema is typical where the prefix before the comma represents the original Python script transformed into a compiled bytecode file, marked by the '.pyc' extension. This decode effectively confirms the relationship of the filename to its Python version, compilation method, and original script.
send
light_mode
delete
Question #24
What is the expected behavior of the following snippet?

It will:

It will:
- Acause a runtime exceptionMost Voted
- Bprint 1
- Cprint 0, [1]
- Dprint [1]
Correct Answer:
A
A

send
light_mode
delete
Question #25
What can you do if you don't like a long package path like this one?


- Ayou can make an alias for the name using the alias keyword
- Bnothing, you need to come to terms with it
- Cyou can shorten it to alpha . zeta and Python will find the proper connection
- Dyou can make an alias for the name using the as keywordMost Voted
Correct Answer:
D
Reference:
https://stackoverflow.com/questions/706595/can-you-define-aliases-for-imported-modules-in-python
D
Reference:
https://stackoverflow.com/questions/706595/can-you-define-aliases-for-imported-modules-in-python
send
light_mode
delete
All Pages