You are on page 1of 22

Kinnaird College for Women

Assignment No.1

Submitted By:
Saira Naveed Elahi
F23MPBC010

Date of Submission:
12-02-2024

Course title:
Genomics, Proteomics & Bioinformatics

Course Instructor:
Dr. Hafiz Muzzammel Rehman

Department of Biochemistry
Fall Semester, 2023

1|Page
1 PYTHON

Python is a high-level, general-purpose programming language. Its design


philosophy emphasizes code readability with the use of significant indentation.
Python is dynamically typed and garbage-collected. It supports multiple
programming paradigms, including structured, object-oriented and functional
programming.
Python consistently ranks as one of the most popular programming languages,
and has gained widespread use in the machine learning community.

Python Uses:
• Python can serve as a scripting language for web applications.
• Python is commonly used in artificial intelligence projects and machine learning
projects with the help of libraries.
• Python can also be used for graphical user interface (GUI) by using libraries
like Tkinter.
• Python can also be used to create games, with libraries such as Pygame, which can
make 2D games.
• Python is used extensively in the information security industry, including in exploit
development.

2|Page
1.1 PYTHON FEATURES

• Easy to Code
Python is a very high-level programming language, yet it is effortless to learn. Anyone can
learn to code in Python in just a few hours or a few days. Mastering Python and all its advanced
concepts, packages and modules might take some more time. However, learning the basic
Python syntax is very easy, as compared to other popular languages like C, C++, and Java.

• Easy to Read
Python code looks like simple English words. There is no use of semicolons or brackets, and
the indentations define the code block. You can tell what the code is supposed to do simply by
looking at it.

• Robust Standard Library


Python has an extensive standard library available for anyone to use. This means
that programmers don’t have to write their code for every single thing unlike other
programming languages. There are libraries for image manipulation, databases, unit-testing,
expressions and a lot of other functionalities.

• Interpreted
When a programming language is interpreted, it means that the source code is executed line by
line, and not all at once. Programming languages such as C++ or Java are not interpreted, and
hence need to be compiled first to run them. There is no need to compile Python because it is
processed at runtime by the interpreter.

• Object-Oriented and Procedure-Oriented


A programming language is object-oriented if it focuses design around data and objects, rather
than functions and logic. On the contrary, a programming language is procedure-oriented if it
focuses more on functions (code that can be reused). One of the critical Python features is that
it supports both object-oriented and procedure-oriented programming.

3|Page
2 PYTHON DICTIONARIES

A Python dictionary is a collection of items that allows us to store data in key: value pairs. We
create a dictionary by placing key: value pairs inside curly brackets {}, separated by commas.
Dictionary keys must be immutable, such as tuples, strings, integers, etc. We cannot use
mutable (changeable) objects such as lists as keys.
We can also create a dictionary using a Python built-in function dict()

Example:
I have created a dictionary of 5 grocery items and their prices. After inserting all the data in a
python, I clicked on the play button, at the start of my data, to show the output.

The grocery dictionary has 5 elements (key-value pairs), where ‘eggs’ is the key and 2.59 is
the value assigned to it and so on.

4|Page
Element 1
Element 2
Element 3
Element 4
Element 5

KEY VALUE

2.1 ACCESS DICTIONARY ITEMS


We can access the value of a dictionary item by placing the key inside square brackets.

We can also use the get() method to access dictionary items.

5|Page
2.2 ADD ITEMS TO A DICTIONARY
We can add an item to a dictionary by assigning a value to a new key.

2.3 REMOVE DICTIONARY ITEMS


We can use the del statement to remove an element from a dictionary. For example,

6|Page
2.4 CHANGE DICTIONARY ITEMS
Python dictionaries are mutable (changeable). We can change the value of a dictionary element
by referring to its key. For example,

2.5 LOOP THROUGH A DICTIONARY


A dictionary is an ordered collection of items therefore it maintains the order of its items. We
can iterate through dictionary keys one by one using a for loop.

7|Page
2.6 COPY A DICTIONARY

You cannot copy a dictionary simply by typing dict2 = dict1, because: dict2 will only be
a reference to dict1, and changes made in dict1 will automatically also be made in dict2. There
are ways to make a copy, one way is to use the built-in Dictionary method copy().

2.7 NESTED DICTIONARIES

A dictionary can contain dictionaries, this is called nested dictionaries.

8|Page
2.8 FIND DICTIONARY LENGTH
We can find the length of a dictionary by using the len() function.

2.9 PYTHON DICTIONARY METHODS


Here are some of the commonly used dictionary methods.

Function Description
pop() Removes the item with the specified key.
update() Adds or changes dictionary items.
clear() Remove all the items from the dictionary.
keys() Returns all the dictionary's keys.
values() Returns all the dictionary's values.
get() Returns the value of the specified key.
popitem() Returns the last inserted key and value as a tuple.
copy() Returns a copy of the dictionary.

9|Page
3 PYTHON LOOPS
Python has two primitive loop commands:

• while loops
• for loops

3.1 PYTHON WHILE LOOPS:

In Python, we use the while loop to repeat a block of code until a certain condition is met. For
example,

In the above example, I have used a while loop to print the numbers from 1 to 8. The loop runs
as long as the condition number <= 8 is satisfied.

10 | P a g e
3.2 THE BREAK STATEMENT
With the break statement we can stop the loop even if the while condition is true.

3.3 THE CONTINUE STATEMENT

With the continue statement we can stop the current iteration, and continue with the next:

11 | P a g e
We can use the continue statement with the for loop to skip the current iteration of the loop
and jump to the next iteration.

3.4 THE ELSE STATEMENT

With the else statement we can run a block of code once when the condition no longer is true:

12 | P a g e
4 PYTHON FOR LOOPS
A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set,
or a string). This is less like the for keyword in other programming languages, and works more
like an iterator method as found in other object-orientated programming languages. With
the for loop we can execute a set of statements, once for each item in a list, tuple, set etc. In
Python, a for loop is used to iterate over sequences such as lists, strings, tuples, etc.

In the above example, I have created a list called colors. As the list has 3 elements, the loop
iterates 3 times.

The value of i is
• Yellow in the first iteration.
• Black in the second iteration.
• Green in the third iteration.

13 | P a g e
4.1 LOOPING THROUGH A STRING
Even strings are iterable objects, they contain a sequence of characters

Here, I have printed each character of the string color using a for loop.

4.2 THE RANGE() FUNCTION

To loop through a set of code a specified number of times, we can use the range() function,
The range() function returns a sequence of numbers, starting from 0 by default, and increments
by 1 (by default), and ends at a specified number.

14 | P a g e
Here, range(3) returns a sequence of 0, 1,and 2.Since the range() function returns a sequence
of numbers, I can iterate over it using a for loop. Here, I used the for loop to iterate over a
range from 0 to 2.

4.3 ELSE IN FOR LOOP

The else keyword in a for loop specifies a block of code to be executed when the loop is
finished:

The else block will NOT be executed if the loop is stopped by a break statement.

15 | P a g e
4.4 NESTED LOOPS

A nested loop is a loop inside a loop. The "inner loop" will be executed one time for each
iteration of the "outer loop".

4.5 THE PASS STATEMENT

for loops cannot be empty, but if you for some reason have a for loop with no content, put in
the pass statement to avoid getting an error.

Having an empty for loop like this, would raise an error without the pass statement.

16 | P a g e
5 PYTHON IF ELSE
In computer programming, the if statement is a conditional statement. It is used to execute a
block of code only when a specific condition is met. For example,
Suppose we need to assign different grades to students based on their scores.

1. If a student scores above 90, assign grade A


2. If a student scores above 75, assign grade B
3. If a student scores above 65, assign grade C
These conditional tasks can be achieved using the if statement.

Python Conditions and If statements

Python supports the usual logical conditions from mathematics:

• Equals: a == b
• Not Equals: a != b
• Less than: a < b
• Less than or equal to: a <= b
• Greater than: a > b
• Greater than or equal to: a >= b

These conditions can be used in several ways, most commonly in "if statements" and loops.
An "if statement" is written by using the if keyword.

5.1 PYTHON IF STATEMENT

An if statement executes a block of code only if the specified condition is met.

Syntax

if condition:
# body of if statement

Here, if the condition of the if statement is:


• True - the body of the if statement executes.
• False - the body of the if statement is skipped from execution.

17 | P a g e
Let's look at an example.

In the above example, I have created a variable named number. Notice the test condition. As
the number is greater than 0, the condition evaluates True. Hence, the body of
the if statement executes.

5.2 PYTHON ELSE STATEMENT

The else keyword catches anything which isn't caught by the preceding conditions.

18 | P a g e
In this example a is greater than b, so the first condition is not true, also the elif condition is
not true, so we go to the else condition and print to screen that "a is greater than b".

5.3 ELIF

The elif keyword is Python's way of saying "if the previous conditions were not true, then try this
condition".

5.4 SHORT HAND IF

If you have only one statement to execute, you can put it on the same line as the if statement.

19 | P a g e
5.5 SHORT HAND IF ... ELSE

If you have only one statement to execute, one for if, and one for else, you can put it all on
the same line:

5.6 AND

The and keyword is a logical operator, and is used to combine conditional statements:

20 | P a g e
5.7 OR

The or keyword is a logical operator, and is used to combine conditional statements:

Example: Test if a is greater than b, OR if a is greater than c:

5.8 NOT

The not keyword is a logical operator, and is used to reverse the result of the conditional
statement:

Example: Test if a is not greater than b

21 | P a g e
5.9 NESTED IF

You can have if statements inside if statements, this is called nested if statements.

5.10 THE PASS STATEMENT

if statements cannot be empty, but if you for some reason have an if statement with no
content, put in the pass statement to avoid getting an error.

22 | P a g e

You might also like