Difference between revisions of "353: Python"

Explain xkcd: It's 'cause you're dumb.
Jump to: navigation, search
(Explanation: Hello World is also easy in other languages, many fixes, more than one way to code can also happen at Python.)
Line 8: Line 8:
  
 
==Explanation==
 
==Explanation==
{{w|Python (programming language)|Python}} is a high-level programming language with a heavily simplified syntax (demonstrated here with the {{w|Hello world program|"Hello, world!" program}}).
+
{{w|Python (programming language)|Python}} is a high-level programming language with a heavily simplified syntax.
  
{{w|Dynamic typing}} means that you do not have to declare a type for any numbers you enter (for example, "short," "float"); the Python program would automatically know how much space to assign.  
+
{{w|Dynamic typing}} means that you do not have to declare a type for any numbers you enter (for example, "short," "float"); the Python program would automatically know how much space to assign and what type has to be used, like in {{w|Visual Basic}} or {{w|JavaScript}}.
  
{{w|Whitespace character|Whitespace}} refers to all invisible text characters, like a space or a tab. In most programming languages, for example, C++, levels inside a program need to be set off by brackets while whitespace is irrelevant. By contrast, in Python you set a level simply by indenting the code.
+
{{w|Whitespace character|Whitespaces}} are invisible text characters, like a space or a tab. In Python you delimit blocks simply by indenting the code, while many other programming languages require brackets or statements like ''BEGIN...END''.
  
Methods, functions and constants in Python are packed in so called ''modules''. To use a module, you would use <code>import ''MODULE''</code>. There are lots of ready-to-use modules available. The comic references this by stating that in order to fly it would suffice to import the <code>antigravity</code> module.
+
Methods, functions and constants in Python are packed in libraries. To use a library, you just have to put this code on top of your source file: "<code>import ''library''</code>". There are lots of ready-to-use libraries available, packed into more than 25,000 "packages".
  
His sampling all the drugs in the medicine cabinet suggests the possibility that he's merely hallucinating flying.
+
[[Cueball]] can fly just because he did import the <code>antigravity</code> library. But more likely it was his sampling of all the drugs in the medicine cabinet, which suggests the possibility that he's merely hallucinating flying.
  
{{w|Perl}} is another programming language. Interestingly, whereas Perl has an adage about there being more than one way to code for a solution, Python directly addresses this by insisting on only one way to code for a solution.
+
{{w|Perl}} is another programming language, but [[Randall]] doesn't like it any more.
  
 
==Transcript==
 
==Transcript==

Revision as of 19:50, 15 August 2013

Python
I wrote 20 short programs in Python yesterday. It was wonderful. Perl, I'm leaving you.
Title text: I wrote 20 short programs in Python yesterday. It was wonderful. Perl, I'm leaving you.

Explanation

Python is a high-level programming language with a heavily simplified syntax.

Dynamic typing means that you do not have to declare a type for any numbers you enter (for example, "short," "float"); the Python program would automatically know how much space to assign and what type has to be used, like in Visual Basic or JavaScript.

Whitespaces are invisible text characters, like a space or a tab. In Python you delimit blocks simply by indenting the code, while many other programming languages require brackets or statements like BEGIN...END.

Methods, functions and constants in Python are packed in libraries. To use a library, you just have to put this code on top of your source file: "import library". There are lots of ready-to-use libraries available, packed into more than 25,000 "packages".

Cueball can fly just because he did import the antigravity library. But more likely it was his sampling of all the drugs in the medicine cabinet, which suggests the possibility that he's merely hallucinating flying.

Perl is another programming language, but Randall doesn't like it any more.

Transcript

[Friend is talking to Cueball, who is floating in the sky.]
Friend: You're flying! How?
Cueball: Python!
Cueball: I learned it last night! Everything is so simple!
Cueball: Hello world is just 'print "Hello, World!"'
Friend: I dunno... Dynamic typing? Whitespace?
Cueball: Come join us! Programming is fun again! It's a whole new world up here!
Friend: But how are you flying?
Cueball: I just typed 'import antigravity'
Friend: That's it?
Cueball: ...I also sampled everything in the medicine cabinet for comparison.
Cueball: But I think this is the python.

Trivia

In response to this comic, the Python developers implemented the module antigravity in version 2.7+. When you import it, the default web browser will open the comic. Also, the module contains a geohashing function.


comment.png add a comment! ⋅ comment.png add a topic (use sparingly)! ⋅ Icons-mini-action refresh blue.gif refresh comments!

Discussion

It is necessary for both Cueballs to sample the medicine cabinet in order for this to be a hallucination. It was probably python. 122.161.29.247 (talk) (please sign your comments with ~~~~)

Or maybe there is just one Cueball - the one on the ground who is hallucinating - because he tried everything...? ;-) Kynde (talk) 20:45, 3 May 2014 (UTC)

'I also sampled everything in the medicine cabinet for comparison' is a possible reference to George's Marvellous Medicine, the children's book written by Roald Dahl, wherein a combination of medicines and household materials produces fantastical effects. Quetzalcoatl (talk) 14:31, 10 February 2014 (UTC)

I think it's related to the invention of photographs, but I'm not sure 173.245.48.81 06:19, 3 January 2015 (UTC)

Woah guys, antigravity is a real module in Python! I was looking around the lib folder, trying to figure out how to put a module into it, and there it was - antigravity.py . It just sends your browser to the comic. --108.162.219.171 22:07, 13 December 2014 (UTC)

Yeah, that's already covered in the Trivia section ;-) --SlashMe (talk) 23:22, 14 December 2014 (UTC)

The implication is that in Python many otherwise amazing things become easily possible after a simple import statement and/or that there is a module for almost anything you'd want to do no matter how difficult.199.27.130.216 16:30, 29 April 2015 (UTC)

The explanation was wrong about many things. Python doesn't have a heavily-simplified syntax--it's about as simple as Perl (and a lot less simple than Lisp); the difference is that it's designed first and foremost to be consistent, easy to read, and easy to remember, even at the cost of occasionally being more verbose or rigid. Its syntax doesn't generally reduce complicated things to a single word; it does allow many complicated things that might take 20 statements in C to be reduced to a single statement, but that's because it's high-level (again, like Perl), not because of its syntax. Dynamic typing has nothing to do with declaring the types of values, much less specifically numeric values, and it has nothing to do with Python automatically knowing how much space to reserve for a value--in fact, it's the opposite; C knows to reserve 4 bytes for an int variable at compile time, whereas Python has no idea what kind of value you're going to put into the variable until runtime. And "like in Visual Basic or JavaScript" is very confused--Visual Basic is statically typed, while JavaScript is dynamically typed, just like Python.

Also, the explanation didn't explain why Cueball's friend was reticent to use dynamic typing or significant whitespace, or what the point of importing modules is.

So I rewrote most of it. 162.158.255.69 20:55, 15 September 2015 (UTC)