Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6 views

Python_Info

Uploaded by

Arshad Ali
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Python_Info

Uploaded by

Arshad Ali
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Python Quick Introduction

Variables And Types

Variables can be made up of alphanumerical characters, however :


Some predefined python keywords cannot be variable names, like if, else, etc.
By convention variable names start with lower case while classes start with upper case

1
Operators

1. Arithmetic Operators

Symbol Operation
+ Addition
- Subtraction
/ Division
// Integer Division
% Remainder
** Power

We can also use different Math Functions using the built-in math library such as:
• math.pi
• math.e
• math.sqrt
• math.pow
• math.sin
• math.cos
• math.tan

2
2. Boolean Operators

1) And
2) Or
3) Not

3. Comparison Operators

Symbol Operation
> Greater Then
< Less Then
>= Division
<= Integer Division
== Remainder

3
Lists
A list is a series of changeable elements
Syntax for list is [....]

1. Indexing

2. Slicing

4
3. Nested Lists

4. List Functions

Different functions can be used on list to change, delete or insert new elements

Tuples
Tuples are like lists, except that they cannot be modified once created, that is they are
immutable.
Syntax for tuples is (....)

5
Dictionaries
Dictionaries are also like lists, except that each element is a key-value pair.
syntax for dictionary is {key1 : value1, ......}

6
Annexure A - Python Installation and Jupyter Notebook
Python Installation and Jupyter Notebook
To start working with Python 3, you will need to have access to the Python interpreter.

Step 1: Download the Anaconda Installer

Download the Anaconda installer.

Step 2: Run the Installer


Once you have chosen and downloaded anaconda, simply run it by double-clicking on the
downloaded file. A dialog should appear that looks something like this:

Select a destination folder to install Anaconda and click Next. Install Anaconda to a directory
path that does not contain spaces or Unicode characters

Step 3: Choose the Python Path


Choose whether to add Anaconda to your PATH environment variable or register Anaconda
as your default Python. We do not recommend adding Anaconda to your PATH environment
7
variable, since this can interfere with other software. Unless you plan to install and running
multiple versions of Anaconda or multiple versions of Python, accept the default and leave
this box checked. Instead, use Anaconda software by opening Anaconda Navigator or the
Anaconda Prompt from the Start Menu.
Step 4: Click on next until Installation is complete

Step 5: Launch Anaconda Navigator and click on install Jupyter Notebook

8
Step 6: Launch Jupyter Notebook

An alternate and simpler approach ( Google Colab Notebooks )

Open Google Colab through the following link https://colab.research.google.com/.


Google Colab comes with pre-installed python and most of its dependencies

Click on new notebook to create your first notebook and start using and learning python

9
Colab / Jupyter Notebook Interface

2. Files: Here you will be able to upload datasets and other files from both your computer
and Google Drive
3. Code Snippets: Here you will be able to find prewritten snippets of code for different
functionalities like adding new libraries or referencing one cell from another.
4. Run Cell: This is the run button. Clicking this will run any code that is inserted in the
cell beside it. You can use the shortcut shift+enter to run the current cell and exit to a
new one.
5. Table of Contents: Here you will be able to create and traverse different sections inside
of your notebook. Sections allow you to organize your code and improve readability.
6. Menu Bar: Like in any other application, this menu bar can be used to manipulate the
entire file or add new files. Look over the different tabs and familiarize yourself with
the different options. Make sure you know how to upload or open a notebook and
download the notebook (all these options are under “File”).
7. File Name: This is the name of your file. You can click on it to change the name. Do
not edit the extension (.ipynb) while editing the file name as this might make your file
unopenable.
8. Insert Code Cell: This button will add a code cell below the cell you currently have
selected.
9. Insert Text Cell: This button will add a text cell below the cell you currently have
selected.
10. Cell: This is the cell. This is where you can write your code or add text depending on
the type of cell it is.
11. Output: This is the output of your code, including any errors, will be shown.
12. Clear Output: This button will remove 10 the output.
12. Ram and Disk: All the code you write will run on Google’s computer, and you will
only see the output. This means that even if you have a slow computer, running big
chunks of code will not be an issue. Google only allots a certain amount of Ram and
Disk space for each user, so be mindful of that as you work on larger projects.
13. Link to Cell: This button will create a URL that will link to the cell you have selected.
14. Comment: This button will allow you to create a comment on the selected cell. Note
that this will be a comment on (about) the cell and not a comment in the cell.
15. Settings: This button will allow you to change the Theme of the notebook, font type,
and size, indentation width, etc.
16. Delete Cell: This button will delete the selected cell.
17. More Options: Contains options to cut and copy a cell as well as the option to add
form and hide code.

11

You might also like