w3resource
Python Exercises

Python: Create a copy of its own source code

Python Basic: Exercise-90 with Solution

Write a Python program to create a copy of its own source code.

Pictorial Presentation:

Create a copy of its own source code

Sample Solution:-

Python Code:

print()
print((lambda str='print(lambda str=%r: (str %% str))()': (str % str))())
print()

Sample Output:

print(lambda str='print(lambda str=%r: (str %% str))()': (str % str))()

Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:

Python Code Editor:

 

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to perform an action if a condition is true.
Next: Write a Python program to swap two variables.

What is the difficulty level of this exercise?