Blog: Desperately Trying to Learn Python – Part One

Share on Google+Share on LinkedInTweet about this on TwitterShare on StumbleUponShare on Facebook

A while ago, a gentleman who worked with me at my previous agency told me that you can use Python to do some awesome scraping action on websites. Obviously, I got needlessly excited and decided that as soon as I was next paid I would go out and get a book about Python and try to learn it.

The book which I got was Introduction to Python Programming by B. M. Harwani. (His personal websites appear to be from the early 90s, but he clearly knows what he’s talking about and I would recommend this book.)

I do wish that it was written a bit more to cater to people who have no clue what the Hell they are doing (like me), but I’m managing by keeping Google close at hand.

Anyway. I guess my main issue with Python, from the get-go, is that I got a D in basic maths at GCSE and don’t even really understand what an integer is.

Of the programming languages I’m looking to learn, Python is one of three – I’m attempting to learn PHP and Javascript too. I like to tell myself that I have enough of a firm grasp on HTML and CSS to make a good go on the other languages. And by firm grasp, I mean ‘more-or-less knowing what I need to Google so I can copy and paste stuff from W3Schools to make a website do what I haven’t been able to make it do by crying at the CMS’.

And so, because I get minimal search visibility for this site, I’m going to archive my progress with Python for my own amusement.

Step One: Downloading Python

Python has it’s own dedicated site, from which you can download what you need to start coding. It’s here.

You’ll want to use Python IDLE for your initial attempts at Python. Whenever you type Python commands into here, another window will open up revealing your results. For the first few attempts, believe me, you’ll get a good number of errors messages.

Step Two: Data Types

Anything beginning with the ‘#’ symbol, and on its own line, won’t be displayed after the calculation commences. It’s a note for yourself more than anything.

Python uses data types; these are:

Integers:

These are 32 bits long, and in Python range from -2,147,483,648 up to 2,147,483,647.

Long Integers:

These can be just as precise as your computer memory dictates.

Floating Point Numbers:

Harwani describes these are ‘double-precision numbers which use 64 bits’. What they actually are are numbers which include a decimal point i.e 1.0. In this instance, 1 alone is an integer.

Boolean:

Meaning the result can only either ‘true’ or ‘false’.

Complex Number:

This is when float types come in. Complex numbers have both ‘imaginary’ and ‘real’ components, which you need to differentiate between with float types.

Imaginary numbers are a multiple of the square root minus one, which you can denote with ‘j’ at the end of the string. If you have 3+5j, that’s a complex number – and the 5 is the imaginary component. The latter equates to the equivalent of 3 x the square root of 3 -1. I think.

Strings:

Strings are the sequences of Unicode characters.

Lists:

These are the values in an ordered sequences.

Tuples:

A list of values (numbers or their representative letters) which are, to put it simply, separated by commas.

Sets:

These are unordered values. An item can only appear once in a set, and each element is indexed.

Dictionaries:

In Python, dictionaries can store any number of Python objects. That includes their container types. They contain keys and their values.

Dict = {‘Cat’: ‘1234’, ‘Kitten’: 4321’, ‘Kitties’: ‘1342’}

Where ‘Cat’, ‘Kitten’ and ‘Kitties’ are keys, and ‘1234’, ‘4321’ and ‘1342’ are values. As such, each value is associated with each key.

If you are one of the three people who actually reads my blog and I’ve said something wrong, please let me know so I can change it.

^.^

 

Written by Sarah Chalk

Sarah Chalk

Sarah is an SEO Account Manager at 360i and has a keen interest in all things SEO. She has also written for a number of sites, including Vue cinema’s film blog and a number of tech websites.

One thought on “Blog: Desperately Trying to Learn Python – Part One

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>