Module 2
2.1 Introduction to Python
Python is a clear and powerful object-oriented programming language. Python is one of the preferred programming languages for working in Test Automation, Web Scraping, Data Analytics, and Machine Learning domains. TIOBE index also ranked it as the third most popular programming languages of 2018.
Python is an interpreted programming language. An interpreted language is a type of programming language for which most of its implementations execute instructions directly and freely, without previously compiling a program into machine-language instructions. The interpreter executes the program directly, translating each statement into a sequence of one or more subroutines, and then into another language (often machine code).
Python has a dynamic type system. Dynamic type checking is the process of verifying the type safety of a program at runtime.
Read more about Python’s Features and Applications
Download Python
For Windows: Click Here
For Mac: Click Here
For Linux: Click Here
Installing Python
For our course, we will be using a Windows machine and you can follow the following steps to install Python in your Windows machine.
For installation on other machines click here .
Installing on Windows
Go to the download python for windos page here, and select the Python 3.x package. Next, launch the download package, follow the steps, and finish the installation.
During installation, select the option “Install for all users” and use the default destination directory.
Next, open the “Start” menu and type “cmd” into the search box. Right-click on the “cmd.exe” link and choose to run as an administrator.
Change the directory to “C:\Python3x” and run the following command to set Python on the system’s path.
setx PATH "%cd%;%path%;" pause
Run Python on Windows
Open Python’s default IDE IDLE.
Once the IDLE window appears, type the following command.
>>> print("Hello World") Hello World!
Python Basics
Commenting
In Python, a single line comment starts with a #
>>> # This is a comment
For multiple line comments, we use the delimiter """
“””” This is a multine comment in Python. It spans more than a single line. “””
Declaring a variable
In Python, the following rules apply when naming a variable.
- It can only be one word.
- It can use only letters, numbers, and the underscore (_) character.
- It cannot begin with a number.
Some examples:
>>> a = 2 >>> a 2 >>> b = 3 >>> a + b 5 >>> word = "Python" >>> word "Python"