Book Image

Learn Python in 7 Days

Book Image

Learn Python in 7 Days

Overview of this book

Python is a great language to get started in the world of programming and application development. This book will help you to take your skills to the next level having a good knowledge of the fundamentals of Python. We begin with the absolute foundation, covering the basic syntax, type variables and operators. We'll then move on to concepts like statements, arrays, operators, string processing and I/O handling. You’ll be able to learn how to operate tuples and understand the functions and methods of lists. We’ll help you develop a deep understanding of list and tuples and learn python dictionary. As you progress through the book, you’ll learn about function parameters and how to use control statements with the loop. You’ll further learn how to create modules and packages, storing of data as well as handling errors. We later dive into advanced level concepts such as Python collections and how to use class, methods, objects in python. By the end of this book, you will be able to take your skills to the next level having a good knowledge of the fundamentals of Python.
Table of Contents (18 chapters)
Title Page
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
2
Type Variables and Operators

Installation


Here we will look forward to the installation of Python on three different OS platforms, namely, Windows, Linux, and Mac OS. Let's begin with the Windows platform.

Installation on Windows platform

Python 2.x can be downloaded from https://www.python.org/downloads. The installer is simple and easy to install. Perform the following steps to install the setup:

  1. Once you click on setup installer, you will get a small window on your desktop screen as shown here; click on Next:
  1. Provide a suitable installation folder to install Python. If you don't provide the installation folder, then the installer will automatically create an installation folder for you, as shown in the following screenshot. Click on Next:
  1. After completion of step 2, you will get a window to customize Python as shown in the preceding screenshot. Notice that the Add python.exe to Path option has been marked x. Select this option to add it to system path variable (which will be explained later in the chapter), and click on Next:
  1. Finally, click on Finish to complete the installation:

Installation on Linux platform

These days most of the Linux-based systems come preloaded with Python, so in most cases, you do not need to install it separately. However, if you do not find your desired version of Python on the Linux platform, you can download your desired version for a particular Linux platform from the site https://www.python.org/downloads/source/. Perform the following steps:

  1. Extract the compressed file using the tar -xvzf python_versionx.x command.
  2. Browse the directory of the compressed file as shown in the screenshot:
  1. Run the following commands:
      [root@localhost Python-2.7.12]# ./configure
      [root@localhost Python-2.7.12]# make
      [root@localhost Python-2.7.12]# make install
  1. Use the command as shown in screenshot to ensure that Python is running:

Installation on Mac OS

For Mac OS, you will get the installer from the site https://www.python.org/downloads/mac-osx/

For the new Mac OS X, Sierra comes loaded with Python 2.7 and it's good for learning but the same cannot be used to develop advanced-level programs. You do not need to separately install Python on the new Mac OS X. However, a word of caution is that the version of Python packed with the Mac OS could be out of date and might require updating. If you still want to install a separate version, you can follow the simple steps mentioned as follows:

  1. First of all, you might require to install Xcode, Xcode is the IDE for  platform and can be downloaded from the Apple appstore.
  2. Once Xcode is installed, you need to install the command-line tools, which can be installed by running the xcode-select --install command on the terminal found under /Applications/Utilities/, as shown in the following screenshot:
  1.  A pop-up window appears with three different options as shown here:
  1. Once you click on Install and agree to their terms and conditions, the command-line tools will start to download and will be installed in few minutes depending on the Internet connection.

 

 

  1. The next step in the process would be to install Homebrew, which is a package manager for Mac OS and handles the Python package. In order to install Homebrew, simply provide the following inputs to the terminal:

      /usr/bin/ruby -e "$(curl -fsSL
      https://raw.githubusercontent.com/Homebrew/install/master/install)"
  1. To install the latest python2 version, simply type brew install python on the terminal:
      $ brew install python

Note

In order to install python3, you need to use brew install python3.