My Assignment - 081404
My Assignment - 081404
My Assignment - 081404
Assignment No.1
Submitted By:
Arfa Ahmad
F23MPBC002
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 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.
• 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.
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 students and their scores. 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 students_scores dictionary has 5 elements (key-value pairs), where Alex is the key and 5
is the value assigned to it and so on.
4|Page
Element 1
Element 2
Element 3
Element 4
Element 5
KEY
VALUE
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.
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,
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().
8|Page
2.8 FIND DICTIONARY LENGTH
We can find the length of a dictionary by using the len() function.
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
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 3. The loop runs
as long as the condition number <= 3 is satisfied.
10 | P a g e
3.1.1.1 The continue Statement
With the continue statement we can stop the current iteration, and continue with the next:
We can use the continue statement with the for loop to skip the current iteration of the loop
and jump to the next iteration.
With the else statement we can run a block of code once when the condition no longer is true:
11 | 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 languages. As the list has 3 elements, the loop
iterates 3 times.
The value of i is
• Swift in the first iteration.
• Python in the second iteration.
• Go in the third iteration.
12 | P a g e
Here, I have printed each character of the string language using a for loop.
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.
13 | P a g e
Here, range(4) returns a sequence of 0, 1, 2 ,and 3.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 3.
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.
A nested loop is a loop inside a loop. The "inner loop" will be executed one time for each
iteration of the "outer loop".
14 | P a g e
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.
15 | 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.
• 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.
Syntax
if condition:
# body of if statement
16 | 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.
The else keyword catches anything which isn't caught by the preceding conditions.
17 | P a g e
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".
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
5.8 NOT
The not keyword is a logical operator, and is used to reverse the result of the conditional
statement:
21 | P a g e
5.9 NESTED IF
You can have if statements inside if statements, this is called nested if statements.
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