Head First Python

I started reading Head First Python, 2nd Edition this week to start learning Python for Automation Testing. I am thoroughly enjoying it so far. It is very helpful that it has images, humour and good lessons in it- it makes it easier and more entertaining to read than just a long book filled with information that can be quite difficult to take in. I have only read chapter 1 so far and i am doing the exercises and making notes as I go.

 

Here are some starting hints that I took down:

  • Python comes with a built-in IDE called IDLE. IDLE lets you create, edit and run your code.
  • IDLE interacts with the Python interpreter (the interpreter runs your code).
  • Python comes with a standard library (provides access to a lot of reusable modules).
  • You make decisions with the if/ elif/ else statement.
  • Functions are inside modules, inside the standard library.

 

Here are a few things I have learnt how to do from this book so far:

1- To find out what system your interpreter is running on:

     >>> import sys

     >>> sys.platform

 

2- To see what version of Python is running:

     >>> print(sys.version)

 

3- To see the name of the folder your code is operating with:

     >>> import os

     >>> os.getcwd()

 

4- To see todays date:

     >>> import datetime

     >>> datetime.date.today()

 

5- To see date as a string:

     >>> datetime.date.isoformat(datetime.date.today())

 

6- To see what the time is:

     >>> import time

     >>> time.strftime (“%H:%M”)

 

7- Iterating over a sequence of objects:

     >>> for i in “Hi!”:

                 print (i)

 

8- Iterating a specific number of times:

     >>> for num in range (3):

                print (‘Python’)

 

9- Use sleep function to pause execution of code:

     >>> import time

     >>> time.sleep (5)

 

10- Generate a random integer

     >>> import random

     >>> random.randint (1,60)

 

I am learning that one of the great strengths of Python is that you can get a lot done with a few lines of code. Most tutorials that I have tried always start with Hello World, but this book dives a little bit deeper than that, which is great. I look forward to learning how to do much more and eventually using Python for Test Automation.