Hashable Objects Must Be Immutable
Fri 01 February 2019 Al Sweigart
A recent post to Reddit sparked some comments, so I wanted to clarify: In Python, hashable objects must be immutable and mutable objects cannot be hashable. (With one exception.)
Writings from the author of Automate the Boring Stuff.
Fri 01 February 2019 Al Sweigart
A recent post to Reddit sparked some comments, so I wanted to clarify: In Python, hashable objects must be immutable and mutable objects cannot be hashable. (With one exception.)
Sun 09 December 2018 Al Sweigart
Alternative Title: The Little Schemer Wears No Clothes
Perhaps a software engineer or MIT professor friend of yours recommended this book to you. “Oh, you want to learn how to code? You should read The Little Schemer,” they’ll say. Your friend means well, but is completely wrong to recommend this book.
Mon 22 October 2018 Al Sweigart
Python's packaging ecosystem contains multitudes. It can be intimidating for new Python developers to try to crack into, especially given the rapid evolution of Python packaging. Writing a *helloworld.py* file and running it on your computer is simple, but getting it to run on someone else's computer (and doing this the "right" way) involves a tangle of terms, tools, and techniques. What are wheel files? What is distutils? Do I use distutils or easy_install or pip?
To get to the bottom of this myself, I've compiled a curriculum of PyCon talks, online documentation, and my own personal notes to finally get a complete handle on Python packaging.
Wed 17 October 2018 Al Sweigart
Programming games are a games genre where instead of playing the game directly, players write bot programs to play the game autonomously. I've created a Zombie Dice simulator, allowing programmers to practice their skills while having fun making game-playing AIs. Zombie Dice bots can be simple or incredibly complex, and are great for a class exercise or an individual programming challenge.
Fri 24 August 2018 Al Sweigart
This page has materials for folks taking my two-hour tutorial, A Beginner's Guide to Tackling Recursion at PyOhio 2018 or following its video recording.
Fri 17 August 2018 Al Sweigart
The Zen of Python by Tim Peters are 20 guidelines for the design of the Python language. Your Python code doesn’t necessarily have to follow these guidelines, but they’re good to keep in mind. The Zen of Python is an Easter egg, or hidden joke, that appears if you run import this
.
Mon 21 May 2018 Al Sweigart
In Python, you can increase the value of a variable by 1
or reduce it by 1
using the augmented assignment operators. The code spam += 1
and spam -= 1
increments and decrements the numeric values in spam
by 1
, respectively.
Other languages such as C++ and Java have the ++
and --
operators for incrementing and decrementing variables. (The name of C++ itself reflects this; the name is a tongue-in-cheek joke that indicates it's an enhanced form of the C language.) Code in C++ and Java could have ++spam
or spam++
. Python wisely doesn't include these operators; they are notoriously susceptible to subtle bugs.
Mon 05 February 2018 Al Sweigart
Before we can get a nuanced answer to "Are tuples mutable or immutable?", we need some background information.
Fri 02 February 2018 Al Sweigart
I often get emails say little more than "Why doesn't my program work?" Often I can't answer them; either I don't have enough information about your problem or you're asking me about something I don't know anything about.
Wed 05 April 2017 Al Sweigart
This post contains the lessons I've learned and my process for creating video tutorials, and I hope others who want to do the same find it useful. While this post is specific to Udemy and programming courses, the same lessons probably apply to all online courses.
Tue 14 March 2017 Al Sweigart
Django is a web app framework for Python (similar to Rails for Ruby). It implements common web app features so you don't have to write that code. Dreamhost is a web host that offers cheap but reliable web servers. Their shared hosting plan is $11 a month, and provides more than enough disk space and bandwidth for personal sites.
Mon 21 September 2015 Al Sweigart
For the last few months I've been putting together an online course that follows my latest (and free) book, "Automate the Boring Stuff with Python". It is now available.
Tue 15 September 2015 Al Sweigart
I've written an article for OpenSource.com called APIs, not apps: What the future will be like when everyone can code, where I write about a coming future where programming ability is in the hands of everyone.
Tue 01 September 2015 Al Sweigart
Tue 10 March 2015 Al Sweigart
The 3rd edition of "Invent Your Own Computer Games with Python" is now available.
Sat 20 December 2014 Al Sweigart
You've written a Python 3 program and want to make it available in other languages. You could duplicate the entire code-base, then go painstakingly through each .py file and replace any text strings you find. Fortunately, Python provides a solution with the gettext
module.
Wed 17 December 2014 Al Sweigart
This tutorial teaches how to write a bot that can automatically play the Flash game Sushi Go Round. The concepts in this tutorial can be applied to make bots that play other games as well.
Thu 11 December 2014 Al Sweigart
Text adventures are an old game genre where the entire world is textually described as a series of rooms. Play involves entering simple text commands such as "move north" or "eat pie". Each room in the game world has its own text description, items on the ground, and exits to adjacent rooms.
Sat 06 December 2014 Al Sweigart
I've organized a large collection of free and non-free books on a new part of this site: The Invent with Python Bookshelf.
Tue 02 December 2014 Al Sweigart
This blog post is those still new to programming and have probably heard about "object-oriented programming", "OOP", "classes", "inheritance/encapsulation/polymorphism", and other computer science terms but still don't get what exactly OOP is used for. In this post I'll explain why OOP is used and how it makes coding easier.