Python Tips and Tricks
Be the best Python programmer you can be. Your guide to writing cleaner, quicker and neater Python code. Plus some handy Python tricks!
Python’s help() Function
In Python, help() is a super useful built-in function that can be used to return the Python documentation of a particular object, method, attributes, etc. This is such a helpful tool for Python beginners to know that many of them are probably unaware of. All you need to do is pass the object or whatever […]
Read MoreUsing the Python Package Index
The Python Package Index (PyPI) is a repository of software created for the Python language. If you’re looking for a package or a module, this is the place to find one. Any of the packages can be easily installed using PIP from the command line. At PyPI, you can download packages OR you can post them, if […]
Read MoreQuick Tip: Where to Report Your Python Bugs
Python’s Bug Tracker is the official page to report any and all Python bugs you may encounter. While it is a good place to go if you think you’ve found a legitimate bug, it’s also a great place to meet other Python developers who may be able to help you (or validate your findings). Using the […]
Read MoreHow to Use Print for More Efficient Code
Here’s a quick tip that will help make your Python code way more efficient if you’re not already taking advantage of it. If you want to print all the values in a list separated by a comma, there are a couple different ways you can go about doing this: there are complicated ways, and then […]
Read MoreQuick Tip: Reversing Strings in Python
There is no built in function in Python for reversing a string, but that doesn’t mean it can’t be done. To reverse a string in Python, a little bit of extended slice syntax needs to be used, so you’re going to have to add something to your code that looks like this: [::-1]. Here’s what […]
Read MoreHow to Build Strings Using .format()
Often developers try to build strings in Python by concatenating a bunch of strings together to make one long string, which definitely works but isn’t exactly ideal. Python’s .format() method allows you to perform essentially the same effect as concatenating strings (adding a bunch of strings together) but does so in a much more efficient […]
Read MoreQuick Tip: The Difference Between a List and an Array in Python
Arrays and lists are both used in Python to store data, but they don’t serve exactly the same purposes. They both can be used to store any data type (real numbers, strings, etc), and they both can be indexed and iterated through, but the similarities between the two don’t go much further. The main difference between […]
Read MoreThe Basics: Concatenating Strings
Concatenating strings basically just means to add a number of strings together to form one longer string. It can be done easily in Python using the ‘+’ symbol. Let’s say you had three strings: “I am”, “Learning”, “Python” To concatenate these, simply add them together using the ‘+’ symbol, like this: >>> print “I am” + “Learning” […]
Read MoreEncoding and Decoding Strings (in Python 3.x)
In our other article, Encoding and Decoding Strings (in Python 2.x), we looked at how Python 2.x works with string encoding. Here we will look at encoding and decoding strings in Python 3.x, and how it is different. Encoding/Decoding Strings in Python 3.x vs Python 2.x Many things in Python 2.x did not change very […]
Read MoreWhat is the difference between __str__ and __repr__ in Python
Purpose of __str__ and __repr__ in Python Before we dive into the discussion, let’s check out the official documentation of Python about these two functions: object.__repr__(self): called by the repr() built-in function and by string conversions (reverse quotes) to compute the “official” string representation of an object. object.__str__(self): called by the str() build-in function and […]
Read More