One of the main differences between Python 3.0 and Python 2.X is the stronger emphasis on iterators. In addition to the iterators associated with built-in types such as files and dictionaries, the dictionary methods keys, values and items return … [Continue reading]
Python Iterators: Part One
Now that we have completed our look at strings, we will begin to look at another useful object: Python iterators. The for loop is often used when we have to iterate over a series of numbers; for example: >>> for x in … [Continue reading]
Python Strings: Part Six
In the previous article, we began our look at indexing and slicing. In this article, we will continue our look at slicing and show some practical applications of slicing. In Python 2.3 and later, there is support for a third index, used as a … [Continue reading]
Python Strings: Part Five
Because strings are defined as ordered collections of characters, we can access their components by position. In Python, characters in a string are fetched by indexing - providing the numeric offset of the desired component in square brackets after … [Continue reading]
Python Strings: Part Four
In the previous articles, we introduced Python strings and covered escape sequences, raw strings and triple-quoted strings. Now we can cover some basic string operations. Strings can be concatenated using the + operator and repeated using the * … [Continue reading]
Python Strings: Part Three
As we saw in the previous article, escape sequences are handy for embedding special byte codes within strings. Sometimes, however, the special treatment of backslashes can cause problems. For example, let's assume we want to open a file called … [Continue reading]
Recent Comments