Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tut] Python One Line Quine

#1
Python One Line Quine

Most computer scientists, programmers, and hackers don’t even know the meaning of the word “Quine” in the context of programming. So, first things first:

What is a Quine?


Roughly speaking, a quine is a self-reproducing program: if you run it, it generates itself.

Here’s a great definition:

:quine: /kwi:n/ /n./ [from the name of the logician Willard van Orman Quine, via Douglas Hofstadter] A program that generates a copy of its own source text as its complete output. Devising the shortest possible quine in some given programming language is a common hackish amusement. (source)

The name “quine” was coined by Douglas Hofstadter, in his popular science book Gödel, Escher, Bach, in honor of philosopher Willard Van Orman Quine (1908–2000), who made an extensive study of indirect self-reference, and in particular for the following paradox-producing expression, known as Quine’s paradox.

Wikipedia

The shortest possible quine is the following empty program:

 

The program is self-reproducing because the output of the program is the program itself. Go ahead and run it in your own shell! ?

Let’s dive into a collection of Python Quines to demonstrate how they work!

Python One-Liner Quine 1


Here’s a short one-liner Quine, I found at this resource:

s='s=%r;print(s%%s,sep="")';print(s%s,sep="")

Here’s the code in an interactive shell so that you can play with this Quine in your browser:

Exercise: Run the code. What’s the output? Can you explain why?

Python One-Liner Quine 2




https://www.sickgaming.net/blog/2020/07/...ine-quine/
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tut] Check Python Version from Command Line and in Script xSicKxBot 0 1,910 08-24-2023, 01:34 PM
Last Post: xSicKxBot
  [Tut] How to Delete a Line from a File in Python? xSicKxBot 0 1,215 09-24-2022, 10:31 AM
Last Post: xSicKxBot
  [Tut] A Simple Guide for Using Command Line Arguments in Python xSicKxBot 0 1,131 08-14-2022, 05:49 PM
Last Post: xSicKxBot
  [Tut] How to Skip a Line in Python using \n? xSicKxBot 0 1,175 07-05-2022, 03:53 PM
Last Post: xSicKxBot
  [Tut] Line Charts — Learning Line Charts with Streamlit xSicKxBot 0 1,352 04-29-2022, 10:52 PM
Last Post: xSicKxBot
  [Tut] How to Read a File Line-By-Line and Store Into a List? xSicKxBot 0 1,349 10-24-2020, 03:12 PM
Last Post: xSicKxBot
  [Tut] Python One Line Dictionary xSicKxBot 0 1,244 09-21-2020, 02:58 PM
Last Post: xSicKxBot
  [Tut] Python One Line Generator xSicKxBot 0 1,310 09-17-2020, 09:29 PM
Last Post: xSicKxBot
  [Tut] Python One Line If Not None xSicKxBot 0 1,316 09-11-2020, 09:45 PM
Last Post: xSicKxBot
  [Tut] Python One Line HTTP Get xSicKxBot 0 1,262 09-11-2020, 07:06 AM
Last Post: xSicKxBot

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016