python tricks
Python hosting: Host, run, and code Python in the cloud!
Fun tricks with Python, a collection of fun tricks for Python 3. They can save you time, make programming code more easy to read and some are entertaining.
You may like:
Python Programming Bootcamp: Go from zero to hero
Starting a simple HTTP web server
A simple HTTP Server can be started in seconds.
|
For Python3:
|
Once started you can open http://127.0.0.1:8000/. The browser will show you the contents of the directory.
A funny text
Try the statement below to display a poem by Tim Peters.
import this |
XKCD web comic
You can open a comic on XKCD using:
import antigravity |
Using Zip to combine arrays
You can zip the two arrays with:
b = [[1, 2, 3, 4], [6, 5, 4, 3]] |
Reverse a list
To reverse a list, you could implement a function. But why go through the trouble if it’s already implemented?
b = [1,2,3,4,5] |
Reverse a string
Instead of creating a method to reverse a string you can use:
s = "Hello world" |
Swapping variables
You do not need to define a temporary variable to swap to variables in Python:
a = 1 |
If you know of any tips or tricks, leave a comment. :-)
You may like:
Python Programming Bootcamp: Go from zero to hero
Leave a Reply:
There are tons of those:
- http://www.siafoo.net/artic...
- http://python.net/~goodger/...
- http://stackoverflow.com/qu...
- http://nbviewer.ipython.org...
-- http://www.abclinuxu.cz/blo...
Hello Frank!
I wanted to know in which order should I study the tutorials in your website(I mean,after Beginner)
Hi, after beginner tutorials you could learn:
Flask (web apps)
GUI programming (pick one of the modules)
Databases
I will create intermediate and more tutorials, stay tuned :-)