Think Python: How to Think Like a Computer Scientist #1

“How to Think Like a Computer Scientist: Learning with Python” is one of the best computer programming books out there that newbies can start with, to learn python or programming. I have been enjoying this book for the past few days and this post is record of what i have learnt in the first 10 chapters.

[well]Once again I highly recommend you to read the PDF of this book for the following reasons.

  1. It teaches you the necessary programming fundamentals that other programming languages require you to know. Once you have learned how to work with python, you might find it easy to learn other programming languages, such as Microsoft Visual Basic, C++ and Java.
  2. This book provides the reader with many simple examples which the reader can try out. This makes the learning experience more interactive and enjoyable.
  3. You can buy the book or download it from the following link: ThinkPython
    [/well]

#Chapter1

Chapter 1 introduces us about python, “The way of the program”, how a program works. It gives us a basic overview about debugging, different types of errors. After several definitions about the behind the scene working of a program we start of with our First Python Program. 

HelloWorld

If you know other programming languages then you may compare the hello world programs side by side and understand that python is a language that will can come naturally to us with just a little knowledge of the syntax in python.

Later on the exercises ask us to try out the online help function of language. For example by running
help(‘print’)
You will get all the information you need about the syntax- print. So if at anytime you are stuck somewhere you can always get quick help from the IDE itself.

The final exercises help to understand how to use the normal math operators in python.

#chapter2

Chapter 2 goes further to tell us about variables, expressions and statements in python.
If you already have learnt programming languages like Java or python you might find the method of declaring variables a bit unconventional.

The datatype of the variable in python is not defined by the user for example in java: int n or double d. The datatype of a variables determined by the value which is initialized for that particular variable and the type of variable can change during the course of program execution.

Lets take an example
[well]i = 99 # data type is implicitly set to integer
i = 99 + 0.99 # data type is changed to float
i = “hundred” # and now it will be a string
[/well]

Python automatically takes care of the physical representation for the different data types, i.e. an integer values will be stored in a different memory location than a float or a string.

The book should give you a comprehensive knowledge about the data types in the second chapter itself.

Statements: Practicing exercises such as Discount Calculator and Volume of Sphere you get a basic and clear understanding of what was taught in the chapter. Here’s another catch thou.

As it was pointed out to me by my mentor Dorai Todla that my statements must follow the PEP8 style guide for writing python programs.

#Chapter3

Chapter 3 tells us about functions which is similar to the functions discussed in any other object oriented programming languages.

Note: The examples showed hence forth have the print statements without the (). If you will use Python 3 or above then your print statements should have ( content ).

It is in this chapter that you will understand- The scope of an object is not determined by the {} or any other brackets which we normally use in other programming languages, but by the help of spaces.

To get a clear understanding of what the above statement meant and importing library classes you will have to do the exercises provided like-  pattern and math Functions.

#Chapter4

Chapter 4 uses the outsourced library package called turtleWorld. This chapter helps us understand how input and output occurs in a computer with a very simple graphical user interface similar to that of MSW LOGO.

#Chapter5

Chapter five is a rather small chapter which deals with the conditions and recursion.

Conditions can be understood by a simple exercise such as fermat’s Number and triangle.
The syntax for conditional statements include: if,else and switch.

Recursion is the idea of calling one function from another ie. the possibility of a function calling itself.

Input: The syntax used in the book for input is

[well] a=raw_input(“Take the input”) [/well]

But if you are using python 3 or higher the following syntax will work best
[well]a=input(“Enter the input”)[/well]

#Chapter6

Chapter 6 helps us understand more about functions and Object Oriented Programming. In this chapter recursion is taken to the next level. The first exercise palindrome gives us insight to what this chapter is all about while GCD includes everything that we’ve ever learnt up until this chapter.

#Chapter7

This chapter is yet another small chapter which talks about the loops specially the while loop. Nothing much to say in this chapter except the exercises square_root, pi and one of the most important programs: eval

#Chapter8

This chapter on strings is one of the most important chapters. It is important for you to understand this chapter strings is something you would use in almost all the programs in the future.

Things to learn in this chapter:
1. len
2. Slicing 
3. Searching 
4. String Methods
5. in Operator

#Chapter9

Chapter 9 is a continuation of the string where the strings are input from the files.

to do so the syntax used is

[well]

with open(‘words.txt’, ‘r’) as wd:
wordList = wd.read().split()

[/well]

The .split function here splits all the words separated by spaces and converts them into lists which can be fount in the next chapter.

#Chapter10

Lists. If you already know about arrays then this might be a little confusing. Python allows you to have arrays in arrays and separate arrays which correspond to arrays which are along side them(dictionary). Its a little confusing and I would recommend you to learn just this one section from codeacademy.

Leave a Reply

Bitnami