Lists in Python

In python Lists are a mutable kind of sequence data type. These lists might be somewhat similar to Arrays in javaScript, but with at least a few note worthy differences such as being a dense rather than sparse kind of array. Lists are not the only option when it comes to arrays in python there is a standard library called array that might prove to be a better option in some cases. However the thing about lists is that it is a type that is built into python itself, and it is just one kind of sever other kinds of sequence types to work with.

In this post I will be going over the basics of lists, how to create them to begin with, how to add and remove elements from them, and also how to sort them. However in the process of doing so I will also be touching base on sequences in general. For example when it comes to built in functions in python there is the list built in function that can be used to create a list, but there is also the range built in function that can be used as a way to create another kind of sequence that is not mutable.

Read More

The fileinput Standard Library in Python

When learning a new programing language such as Python one thing that comes to mind that I like to learn about right away os how to go about reading from the standard input. When it comes to Python there is the fileinput library that can be used to read from the standard input, but can also be used as a way to read a collection of files also. There is one main function of interest in this library when it comes to reading standard input and that would be the input method, by default it will read from the standard input if no file list is given.

There are some additional features of the fileinput library also though, on top of reading from the standard input the fileinput library can be used as a way to read a collection of files. Also there are some related topics that come to mind when using the fileinput library such as piping in a posix system, the open built in function when it comes to reading just one file, and also the subprocess library when it comes to getting a collection of file names. So in this post I will of course be going over a basic example of reading from the standard input with the fileinput library, but will also be going over some more examples that touch base on other related python topics.

Read More

The Threading Standard Library in Python

This month I wanted to start learning python, and I have went threw the basics of learning the language pretty fast. However now I am starting to scratch the surface when it comes to the wide range of standard libraries that there are to work with. One library that I think I should at least write a few quick examples with at least would be the threading library.

In javaScript there are methods like setInterval, and setTimeout that can be used as a way to delay the calling of a function. These methods however will not result is a new event loop though, however in client side javaScript there is Webworker, and in node there is the cluster module that can be used as ways to go about creating a whole other event loop to work in. In python there must be ways of doing the same things, that is just delaying the calling of a function in the same thread, and also to create a whole separate thread. This it would seem is what the threading standard library is all about when it comes to doing the same things in a python environment.

Read More

The Math Standard Library in Python

Time to wrap up this first week of learning python on my own, today I think I will be taking a look at one of the many standard libraries to work with in python starting with the math library.

In javaScript there is the built in Math object that contains all kinds of useful properties and methods that help with working out all kinds of Math expressions. So when it comes to Python there should be another such Object, or built in module at least to work with and it would seem that there is. However things are a little broken up with some things, for example when it comes to absolute value there is a built in absolute value method in python itself, and there is another such method in the math module. Also when it comes to generating random numbers there is no such method to be found in the standard math module, instead there is yet another module called random that contains such a method. So depending on what I need to do, it would be best to look at what there is to work with on built in functions first. Then if I might look at the math module, but even then there is more than one math module.

Anyway in todays post I am going to be looking at some of the methods that there are to work with when it comes to the standard built in math library in python. I will also be taking a look at some other features of python itself, and other libraries to work with in order to truly get up and running with some math in python.

Read More

Functions in Python

I am still in the process of learning python, and one important aspect of learning python, or any language for that matter, is to know how to define functions. Functions are a great way to go about taking a block of code that I find myself repeating over and over again, and turn it into a function that I can just call each time I need to repeat that block of code. With functions often there is a way to pass a few arguments that will be used in the body of the function, and there should also be a way to return a value from inside a function also. In python it is possible to do these basic things with functions, but there is also much more to them beyond that of course.

Coming from a javaScript background I have a lot of concerns, such as if python supports high order functions or not ( the answer is yes ). Still I need to start somewhere, and that means just staring out with some basic python function examples, and then move on more complex topics such as high order functions. So this will be a basic getting started with functions in python type post, but maybe I will get into some more advanced examples of python functions also in the process.

Read More