Ipython in The Terminal. & Quit The Ipython Interpreter by Using CTRL + D
Ipython in The Terminal. & Quit The Ipython Interpreter by Using CTRL + D
Ipython in The Terminal. & Quit The Ipython Interpreter by Using CTRL + D
Laod Data from the file and plot that data Single column format Multiple columns
separated by spaces or other delimiters we have the file info .txt with three columns of data
separated by \:".Read it into 3 separate simple sequences. Using Command
x = loadtxt(\info.txt",unpack=True, delimiter=":")
Different type of plotting graph technique used like scatter log log
scatter() function is used to generate the scatter graph
Syntax : scatter(x,y)
x - a sequence of data y - a sequence of data having same length as that of x
Log-log graph is a two-dimensional graph of numerical data It uses logarithmic scales on both
axes Graph appears as straight line due tonon-linear scaling
Syntax : loglog(x, y)
x - a sequence of data y - a sequence of data, having the same length of x
A pie chart is a circular chart dividedinto sectors, to illustrate numerical proportion
Syntax :pie(values, labels = labels)
values - the data to be plotted labels - the label for each wedge in the pie chart
Plot a pie chart with the same data with colors for each wedges
A bar chart is a chart with rectangular bar with lengths proportional to the values that they
represent
Syntax :bar(x, y)
- a sequence of data y - a sequence of data, the same length of x
Help about matplotlib can be obtained from matplotlib.sourceforge.net/contents.html
More plots can be seen at matplotlib.sourceforge.net/ users/screenshots.html
Day 2
Creating List
List can store a sequence of elements All elements need not be of the same data types
Syntax: ListName=[name of list item seprated by comma of different type]
Ex. List=[1,2 3,4 ,5]
To access the any item from list by using index starting with 0
List[0] we get 1
To access the last element of list used List[-1] we get 5
Variable must either start with an alphabet or an underscore They cannot start with numbers and cannot
be the same as syntax: Variablename
Python keywords
for, if, else, elif, while, in, def, or,and
A variable name cannot haves paces or punctuation charactersor any arithmetic characters
Valid names: x, y, xx, abc, a b c, a1, variable1,mylist, x foreign, spi_, while true, or else,
Invalid names:x, 2 var, x-, x+, x;, x: x y, x+y x*y x&^ae, for, in, elif
We can also create a list inside a list This property makes lists heterogeneous data structures
Syntax: variable = [list1[list2]] ex .doublelist=['a', ['b','c','d'], 'and', 5, 6, 7, 8]
doublelist[1][2]
len() function is used to check the number of elements in the list
Syntax:len(variable)
We can append elements to the list using the append function This function will add the element
to the end of the list
Syntax: variable.append(element)
We can also remove elements from lists One is by using the index with del keyword
Syntax:del variable[index]
The other way is removing element by the value using remove function
Syntax: variable.remove(element)
for statement iterates over the members of a sequence in order, executing the block each time
syntax:
for <loop variable> in sequence:
<statement 1>
<statement 2>
...
<statement n>
For Generates a list of integers range function is uesd
Syntax :
range([start,] stop[, step])
ex.range(1, 20, 2)
generates integers from 1 to 19with step of 2
String
In Python, any character within a single/ double/ triple quotes is a string
Ex. 'This is a string' and "This is a string too" also "'This can be a large string"'
We can split and join the strings by using the functions :
split() and join()
To join a string: str.join(sequence)
To split a string: str.split()
Split a string using a delimiter
Remove the leading, trailing and all whitespaces in a string
Convert between di_erent built-in datatypes
Arrays
Arrays are homogeneous data structures
A = array([1, 2, 3, 4, 5])
To arrange the elements in an array we use arange method
Syntax: arange([start,] stop,[ step,] dtype=None)
We will use reshape method to change the shape of an array
Syntax: object.reshape(rows, columns)
Identity method It is a square matrix of order (n,n) with ones on the main diagonal and all other
elements as zeros. Syntax: identity(n)
Zero method It creates an m X n matrix with all elements as 0 Syntax: zeros((m, n))
Negative Indexing Python programming supports negative indexing of arrays This means the
index value of -1 gives the last element and -2 gives the second to last element of an array
Slicing of an array is done toaccess parts of an array Slicin g syntax is [start:stop]
Striding uses the step value to jump between the elements in anarray Striding syntax is
[start:stop:step]
Day3
Data type & operator
There are 2 type of datatype used in python
Number -int ,float,complex
Boolean
Operators Arithematic and Boolean
Sequence datatype – List , String , Tuple Accessing the above data types using index
Taking Input from user :
% string operator is called as format operator
For example:
%d - speci_es the integer format
%s - speci_es the string format
%f - denotes the oat format
Take input from user by using input()
Matrix operation:
Crating matrix using list perform all Mathematical Operation on it also find Determinant
of a matrix Inverse of a matrix and Eigen values and Eigen vectors of a matrix. Use the function
det() to find the determinant of a matrix. inv() function to find inverse of matrix and Find out
the eigen vectors and eigen values of a matrix, using functions eig() and eigvals() all this
function present into numpy.linalg module.
Looping Statement:
While loop:
Syntax:
while <condition>:
#True block statements
#update condition variable
#statements after while loop
For Loop:
Syntax:
For value in range(values ,Step)
Iterate over a sequence using for and while loops
Break out of loops using break statement
Skip iterations using continue statement
Use the pass statement in a loop
Conditional Statement:
If Statement:
Syntax:
if <condition>:
#statements
If else Statement
Syntax:
if <condition>:
#True block statements
else:
#False block statements
elif Statement:
Syntax:
if <condition-1>:
#statements when cond-1 True
elif <condition-2>:
#statements when cond-2 True
else:
#statements when all conditions Fail
Ternary operator
It allows to test a condition in a single line replacing the multiline if-else It can reduce code size
and increase readability of the code
Syntax:
[A] if <condition> else [B]
Day4
Manipulating List:
Slicing
Syntax: p[start:stop]
Returns all the elements of p between start and stop The element with the stop index value will
not be included
Sorting
Python provides a built-in function called sorted sorted() sorts the list which is passed as an
argument to it It returns a new sorted list
Syntax
Sorted (Listname,Order)
Reverse
Reverse function used the Reverse lists
Manipulating Steing:
tring slicing allows us to obtain
substrings
Syntax:
string name[start:stop]
string name[start:stop:step]
upper() lower() replace() join()
Function :
Syntax:
def function_name(parameters):
"""docstring"""
statement(s)
return [expression]
Python also provides built-in functions, some are abs() any() dir() and help()
More built in function we get https://docs.python.org/3/library/functions.html
Sets:
Sets are unordered collections of unique elements The set itself is mutable We can add or
remove items from it Make sets from lists or by using curly braces Perform union, intersection
and symmetric difference operations. If a = [1, 1, 2, 3, 3, 5, 5, 8], then Set a= {1, 2, 3, 5, 8}
Tuples:
Tuple is a collection of elements similar to a list Tuple uses parentheses, whereas list
uses square brackets Elements of a tuple cannot be changed once it is assigned But in a list,
elements can be changed
Dictionaries:
Dictionary is an unordered collection of items which has key:value pairs
Dictionary is used to look up for a specific key and retrieve the corresponding value
Keys are unique within a dictionary while values may not be The values of a dictionary can be
of any data type But the keys must be of immutable data type such as strings, numbers or tuples
The value of a dictionary can be accessed using the corresponding keys
Syntax
dictionary name[key]
The method in will return True if the key is found in the dictionary It will return False if
key is not present Note that we can check only for the presence of the keys in dictionaries and
not values Keys of a dictionary are not Ordered Hence, slicing and striding are not valid on
dictionaries keys() is used for getting a list of the keys and values() is used for getting a list of
values
Module :
We can write Python modules to bundle functions We can then make use of these
functions by importing modules to other scripts Test code should only be executed when we run
the python script independently To execute the test code when the module is imported to other
scripts, we can use name variable
Every Python _le can be run in two ways:
1. As an independent stand-alone script or
2. As a Python module which can be imported by other Python scripts or modules
Handling Error:
In Python there are two kinds of errors Syntax errors And Exceptions
Syntax errors are caused by incorrect usages and these are detected by parser
Example: if True print(\done")
Exception is an error that occurs during execution of a program Python generates an
exception that can be handled, which avoid the program to crash
try:
statement1
statement2
except exception name:
exception handling statement(s)
else:
statement(s) when no exception
after statement(s)
Day5
Django
A Django project is a collection of Settings for an instance of Django, Database
configuration ,Django specific options And Application specific settings
Django Model
A Django model is a simple Python class A Model class represents a database table A Model
attribute represents a table field (each column in the table) We write Django models in the
models.py file
Django admin app
The Django admin app is a feature that provides an interface to Create Read and Update also I
Delete model instances
Creating_Views_and_Design_URLs
A view is a code that accepts a Request It processes the request and sends back a response
Creating_HTML_Template_in_Django
Django_shell_Django_Database_Query
Creation_Forms_in_Django
Using_CSS_and_JavaScript_in_Django
Django_Authentication
Writing_Tests_in_Django
Name: prof.Kauser Salim Mujawar
Designation: Assistant Professor
Email Id:mujawarkauser@gamil.com
Phone No:8888439860
College name: Government college of Engineering, Karad
Gourp No: 3