Functions, Exception, Modules and Files
Functions: Difference between a Function and a Method, Defining a Function, Calling a Function, Returning Results from a Function, Returning Multiple Values from a Function, Functions are First Class Objects, Pass by Object Reference, Formal and Actual Arguments, Positional Arguments, Keyword Arguments, Default Arguments, Variable Length Arguments, Local and Global Variables, The Global Keyword, Passing a Group of Elements to a Function, Recursive Functions, Anonymous Functions or Lambdas (Using Lambdas with filter() Function, Using Lambdas with map() Function, Using Lambdas with reduce() Function), Function Decorators, Generators, Structured Programming, Creating our Own Modules in Python, The Special Variable __name__
Exceptions: Errors in a Python Program (Compile-Time Errors, Runtime Errors, Logical Errors),Exceptions, Exception Handling, Types of Exceptions, The Except Block, The assert Statement, UserDefined Exceptions, Logging the Exceptions
20%
Files: Files, Types of Files in Python, Opening a File, Closing a File, Working with Text Files Containing Strings, Knowing Whether a File Exists or Not, Working with Binary Files, The with Statement, Pickle in Python, The seek() and tell() Methods, Random Accessing of Binary Files, Random Accessing of Binary Files using mmap, Zipping and Unzipping Files, Working with Directories, Running Other Programs from Python Program
A function is a set of statements that take inputs, do some specific computation and produces output. The idea is to put some commonly or repeatedly done task together and make a function, so that instead of writing the same code again and again for different inputs, we can call the function.
Python provides built-in functions like print(), etc. but we can also create your own functions. These functions are called user-defined functions.
Functions, Exception, Modules and Files
Functions: Difference between a Function and a Method, Defining a Function, Calling a Function, Returning Results from a Function, Returning Multiple Values from a Function, Functions are First Class Objects, Pass by Object Reference, Formal and Actual Arguments, Positional Arguments, Keyword Arguments, Default Arguments, Variable Length Arguments, Local and Global Variables, The Global Keyword, Passing a Group of Elements to a Function, Recursive Functions, Anonymous Functions or Lambdas (Using Lambdas with filter() Function, Using Lambdas with map() Function, Using Lambdas with reduce() Function), Function Decorators, Generators, Structured Programming, Creating our Own Modules in Python, The Special Variable __name__
Exceptions: Errors in a Python Program (Compile-Time Errors, Runtime Errors, Logical Errors),Exceptions, Exception Handling, Types of Exceptions, The Except Block, The assert Statement, UserDefined Exceptions, Logging the Exceptions
20%
Files: Files, Types of Files in Python, Opening a File, Closing a File, Working with Text Files Containing Strings, Knowing Whether a File Exists or Not, Working with Binary Files, The with Statement, Pickle in Python, The seek() and tell() Methods, Random Accessing of Binary Files, Random Accessing of Binary Files using mmap, Zipping and Unzipping Files, Working with Directories, Running Other Programs from Python Program
A function is a set of statements that take inputs, do some specific computation and produces output. The idea is to put some commonly or repeatedly done task together and make a function, so that instead of writing the same code again and again for different inputs, we can call the function.
Python provides built-in functions like print(), etc. but we can also create your own functions. These functions are called user-defined functions.
learn how to program with python
from scratch to be an expert
use the link in the first slide to get the full course
here is the link if you want : https://oke.io/JdxdUl
the link of the documentation : https://oke.io/J6DeY3
link to download python : https://oke.io/BENgRLR2
learn how to program with python
from scratch to be an expert
use the link in the first slide to get the full course
here is the link if you want : https://oke.io/JdxdUl
the link of the documentation : https://oke.io/J6DeY3
link to download python : https://oke.io/BENgRLR2
In this chapter we are going to get familiar with some of the basic presentations of data in programming: lists and linear data structures. Very often in order to solve a given problem we need to work with a sequence of elements. For example, to read completely this book we have to read sequentially each page, i.e. to traverse sequentially each of the elements of the set of the pages in the book. Depending on the task, we have to apply different operations on this set of data. In this chapter we will introduce the concept of abstract data types (ADT) and will explain how a certain ADT can have multiple different implementations. After that we shall explore how and when to use lists and their implementations (linked list, doubly-linked list and array-list). We are going to see how for a given task one structure may be more convenient than another. We are going to consider the structures "stack" and "queue", as well as their applications. We are going to get familiar with some implementations of these structures.
Mind map of Python (basic)
By Gohar
references:
Automate the stuff boring with Python( 2nd edition), Al Sweigart
Learn web development with Python, Fabrizio Romano, Gaston C. Hillar and Arun Ravindran
The objective of the Level 5 Diploma in Information Technology is to provide learners with an excellent foundation for a career in a range of organisations. It designed to ensure that each learner is ‘business ready’: a confident, independent thinker with a detailed knowledge of Information Technology, and equipped with the skills to adapt rapidly to change.
Vibrant Technologies is headquarted in Mumbai,India.We are the best Python training provider in Navi Mumbai who provides Live Projects to students.We provide Corporate Training also.We are Best Python classes in Mumbai according to our students and corporators
Vibrant Technologies is headquarted in Mumbai,India.We are the best Python training provider in Navi Mumbai who provides Live Projects to students.We provide Corporate Training also.We are Best Python classes in Mumbai according to our students and corporators
We all have good and bad thoughts from time to time and situation to situation. We are bombarded daily with spiraling thoughts(both negative and positive) creating all-consuming feel , making us difficult to manage with associated suffering. Good thoughts are like our Mob Signal (Positive thought) amidst noise(negative thought) in the atmosphere. Negative thoughts like noise outweigh positive thoughts. These thoughts often create unwanted confusion, trouble, stress and frustration in our mind as well as chaos in our physical world. Negative thoughts are also known as “distorted thinking”.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
How to Create Map Views in the Odoo 17 ERPCeline George
The map views are useful for providing a geographical representation of data. They allow users to visualize and analyze the data in a more intuitive manner.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
This is a presentation by Dada Robert in a Your Skill Boost masterclass organised by the Excellence Foundation for South Sudan (EFSS) on Saturday, the 25th and Sunday, the 26th of May 2024.
He discussed the concept of quality improvement, emphasizing its applicability to various aspects of life, including personal, project, and program improvements. He defined quality as doing the right thing at the right time in the right way to achieve the best possible results and discussed the concept of the "gap" between what we know and what we do, and how this gap represents the areas we need to improve. He explained the scientific approach to quality improvement, which involves systematic performance analysis, testing and learning, and implementing change ideas. He also highlighted the importance of client focus and a team approach to quality improvement.
2. Dictionaries
Stores unordered, arbitrarily indexed data
Consists of key-value pairs
Dict = {key:value, key:value, key:value...}
Note: keys must be immutable!
ergo: numbers, tuples or strings
Values may be anything, incl. another
dictionary
Mainly used for storing associations or
mappings
3. Create, add, lookup, remove
Creation:
mydict = {} (empty), or
mydict = { mykey:myval, mykey2:myval2 }
Adding:
mydict[key] = value
Lookup:
mydict[key]
Remove:
del mydict[key]
4. Dictionary methods
All keys:
mylist.keys() - returns list of keys
All values:
mydict.values() - returns list of values
All key-value pairs as list of tuples:
mydict.items()
Get one specific value:
mydict.get(key [, default])
if default is given, that is returned if key is not present in the
dictionary, else None is returned
Test for presence of key:
key in mydict – returns True or False
5. Dictionary exercise
Log in to freebee as before
Do module load python, then start python
Create this dictionary:
{“A”: 1, 1:”A”, “B”:[1,2,3]}
Find out the following:
how many keys are there?
add “str”: {1:”X”} to the dictionary
is there something stored with key “strx?”
what about the key “str”?
remove the number 3 from the list stored under “B” -
print the results
6. Sets
Similar to lists but:
no order
every element is unique
Can create set from list (duplicates are then
removed)
Add elements with
myset = set()
myset.add(elem)
Neat trick - how to create unique list:
newlist = list(set(oldlist))
7. Set operations
Intersection – found in both sets
set1.intersection(set2)
Union – all elements from both sets
set1.union(set2)
Difference
set1 – set2
Symmetrical difference
set1.symmetric_difference(set2)
8. Set exercise
Create these lists:
[“a”, “B”, 1, “a”, 4], [“c”, 1, 2, “A”, “c”, “a”]
make sets from these two lists
Figure out:
the number of unique elements in each list
the elements present in both
the elements that are not shared
the number of unique elements altogether
the elements that are present in the second set,
but not in the first
9. Input from terminal
Can get input from terminal (user)
Code:
variable = raw_input(“Promt text”)
Prompt text will be printed to screen and the
text the user types in will be stored in
variable
10. Indentation and scope
Python does not use brackets or other
symbols to delineate a block of code
Python uses indentation – either tab or
space
Note: variables can only be seen and used
within the block of code it is in – this is
called scope
11. Flow control
Flow control determines which blocks of
code that will to be executed
One conditional statement
If – else
Two iteration statements
For: iterate over group of elements
While: do until something is true
12. If
Structure:
if <boolean expression>:
code block 1
elif <boolean expression>:
code block 2
else:
code block 3
Only one of these code blocks are executed
Executed block: the one whose expression
first evaluates to True
13. Boolean expressions
Comparisons
A> B A greater than B
A< B A smaller than B
A >= B A greater than or equal to B
A <=B A smaller than or equal to B
A == B A equal to B
A != B A not equal to B
Comparisons can be combined:
and, or, and not
B != C and B > A - results evaluated left-right
Other values
True: non-empty lists, sets, tuples etc
False: 0 and None
14. If exercise
Use the interactive python shell
Create the following:
Empty list
List with elements
A variable with value 0
A variable with value -1
A variable with value None
Use these in an if structure to see which
ones that evaluate to True
15. If script
Create variable that takes input from user
Test to see if:
The sequence contains anything else than
ATGC
The sequence is at least 10 nucleotides long
Report results to user
16. If script
inputstring = raw_input("Input your DNA string: ")
mystring = inputstring.upper()
mylength = len(mystring)
myAs = mystring.count("A")
myCs = mystring.count("C")
myTs = mystring.count("T")
myGs = mystring.count("G")
nucleotidesum = myAs + myCs + myTs + myGs
if nucleotidesum < mylength:
print "String contains something else than DNA"
elif mylength < 10:
print "Length is below 10"
else:
print "Sequence is ok"
17. For
Structure:
For VAR in ITERABLE:
code block
Code block executed for each element in
ITERABLE
VAR takes on value of current element
Iterables are:
Strings, lists, tuples, xrange, byte arrays,
buffers
18. For example
Use the python interactive shell
Create string “ATGGCGGA”
Print out each letter in this string
>>> a = "ATGGCGGA"
>>> for var in a:
... print var
...
A
T
G
G
C
G
G
A
>>>
19. For exercise
Define list of numbers 1-9
Show each number multiplied with itself
>>> a = [1,2,3,4,5,6,7,8,9]
>>> for var in a:
... print var*var
...
1
4
9
16
25
36
49
64
81
>>>
20. xrange
Iterate over a range of numbers
xrange(int): numbers from 0 to int
xrange(start, stop, step):
Start at start, stop at stop, skip step
between each
>>> for i in xrange(0,10,2):
... print i
...
0
2
4
6
8
>>>
21. For exercise
Create dictionary where:
Keys are all combinations of A, B, C
Values are increasing from 1 and up
Hints
Can use two for loops
Adding to an integer variable:
i += 1
22. For exercise
letters = "ABC"
valuedict = {}
i = 1
for letter1 in letters:
for letter2 in letters:
k = letter1 + letter2
i += 1
valuedict[k] = i
print valuedict
[karinlag@freebee]~/tmp/course% python forloopdict.py
{'AA': 2, 'AC': 4, 'AB': 3, 'BA': 5, 'BB': 6, 'BC': 7,
'CC': 10, 'CB': 9, 'CA': 8}
[karinlag@freebee]~/tmp/course%
23. While
Structure
while EXPRESSION:
code block
Important: code block MUST change truth
value of expression, otherwise infinite loop
24. While example
>>> a=10
>>> while True:
... if a<40:
... print a
... else:
... break
... a += 10
...
10
20
30
25. Break
Can be used to break out of a loop
Can greatly improve legibility and efficiency
What happens when next tuple is iterated
over, after 'blue' is found?
26. Homework
ATCurve.py
take an input string from the user
check if the sequence only contains DNA – if
not, promt for new sequence.
calculate a running average of AT content along
the sequence. Window size should be 3, and
the step size should be 1. Print one value per
line.
Note: you need to include several runtime
examples to show that all parts of the code
works.
27. Homework
CodonFrequency.py
take an input string from the user
check if the sequence only contains DNA
– if not, promt for new sequence
find an open reading frame in the string (note,
must be multiple of three)
– if not, prompt for new sequence
calculate the frequency of each codon in the
ORF