Notes Xi List
Notes Xi List
-----------------------------------------------------------------------------------
--------------------------------------------------------------------------
list are mutable sequence of python
mutable = changable
lists are collection of elements which can store into the single variable, the
lists are depicted through square brackets [],
e.g
a = 10
a = [10]
a = [10,9,8,7]
-----------------------------------------------------------------------------------
--------------------------------------------------------------------------
TYPES OF LIST:
1.Empty list
li = []
2.Number list:
li = [1,2,3,4,5,6,7,8]
(only whole numbers no decimal)
3.Decimal list
li = [1.2,2.56,5.67]
4.String/test/character list:
li = ['name_1','name_2','name_3']
5.Mixed List
li = [1101,'name',23.32] (heterogenious)
say
li = [1,2,3,4,5]
[1][2][3][4][5]
index number = 0 1 2 3 4
Syntax:
print (li[index_n0.])
e.g.
li = [1,2,3,4,5] Output: 1
print (li[0])
print (li[1]) Output: 2
e.g.
li = [1,2,3,4,5]
print (li[1:4]) Output: [2 , 3 , 4]
e.g.
li2=['a','e','i','o','u']
print (li2)
print(li2[2])
li2[2]='z'
print (li2)
-----------------------------------------------------------------------------------
--------------------------------------------------------------------------
*FUNCTIONS
*TYPES OF FUNCTIONS
1.LIBRARY FUNCTION
- it is also known as built i or ready made function.
[23][34][67][78]{234}{345}
^ ^
| |
appended elements
#.extend() - same as append()
###e.g.{extend}
li = [1,2,3,4,5]
li.extend([90,56])
print (li)
li.append([67,78,70])
li = [][][][]{67}{78}{70}
index no. 1 2 3 4 5
li.extend([67,78,90])
li = [][][][]{67}{78}{90}
index no. 1 2 3 4 5 6 7
#insert(_,_)
to add a value as per the list (can add a value in between)
Synatx:
listname.insert(indexno,your value)
###e.g.
li = [1,2,3,4,5]
print (li)
output:[1, 2, 3, 4, 5]
li = [1,2,3,4,5]
li.insert(2,78)
print (li)
output:[1, 2, 78, 3, 4, 5]
#del
###e.g.
li = [1,2,3,4,5]
del li[3]
print(li)
OUTPUT:[1, 2, 3, 5]
OUTPUT:
[8, 9, 10, 11, 12, 13, 14, 15]
#pop()
###e.g.
li = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
li.pop(4)
print(li)
###e.g.
li = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
li.pop()
print(li)
#if no index no. is alloted then the last element will get deleted
OUTPUT:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
#clear()
clears the entire list (does not require an attribute in newer versions)
#remove()
delets one or more specified elements
###eg.
li = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
li.remove(7)
print(li)
OUTPUT:
[1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15]
a + b
('a' and 'b' are operands)
('+' binary operator)
###e.g.
li = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
li2 = [56,57,58,59,60,61,62,63,64,65]
print (li+li2)
OUTPUT:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65]
###e.g.
li = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
li2 = [56,57,58,59,60,61,62,63,64,65]
print (li+3)
OUTPUT:
TypeError: can only concatenate list (not "int") to list
###e.g.
li = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
li2 = [56,57,58,59,60,61,62,63,64,65]
print (li+li2)
print ("Example 2:")
print (li*3)
Output:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65]
Example 2:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
###e.g.
li3 = ['a','b','c','d','e','f']
li4 = ['q','w','e','r','t']
print (li3+li4)
print (li3*4)
OUTPUT:
['a', 'b', 'c', 'd', 'e', 'f', 'q', 'w', 'e', 'r', 't']
['a', 'b', 'c', 'd', 'e', 'f', 'a', 'b', 'c', 'd', 'e', 'f', 'a', 'b', 'c', 'd',
'e', 'f', 'a', 'b', 'c', 'd', 'e', 'f']
###e.g.
li3 = ['a','b','c','d','e','f']
li4 = ['q','w','e','r','t']
print (li3>li4)
print (li3>4)
OUPUT:
False
True
e.g.
li = [1,2,3,24,5,65,7,8,96,10,11,12,13,14,15]
print (li[2:9:1])
OUTPUT
[3, 24, 5, 65, 7, 8, 96]
UNIT-II DATA MANAGEMENT
-------------------------
1. Primary key:
a column or set of columns which contains a unique data known as primary key. It
cannot be blank or null value.
2. Candidate key:
all the columns of the table which serve as the primary key are known as candidate
key
3. Alternate key:
the candidate keys which are not acting as primary key are known as alternate keys
4. Foreign Key:
foreign key is a column which is used to relate to or more than two tables, it is
compulsory that a foreign key column in first table should be
primary key in related table.
# REFRENCIAL INTEGRITY
- Its is a system of rules that a dbms uses to ensure the relationship between
records in a related table are valid...
SQL
app name : sql (sequencial query language)
<----------Request-------------
[ ] [ ]
[ ] [ ]
Server client
------------Response------------->
___________________________
to filter out bad requests
___________________________
[ ] { } [ ] {3 tier
architecture}
[ ] { } [ ]
___________________________________________________________________________________
_______________
Commands:
1. DDL (data defination language)
- to create new things
arithmetic operations:
ADITTION:
--------
starting:
use managerie
show databases;
show tables;
--------------------------------------
here sal % comm is formed from the addition from sal% and comm
---------------------------------------------------------------------
Q# display the name of the student and their updates marks by 5
#Distinct:
(it is a keyword that can be used to hide duplicate value(s))
List jobs provided in your company:
# "where"
- where is a cluase or keyword which is used to retrieve or fetch raw specific
data...
(-relational operator/conditional operator)
|start:
|- show databases
|- use menagaerie
|- show tables;
|- select * from (table_name)
Q# to show name of students who got above 400 marks...
- open sql
- use menagarie
- show tables;
- select * from student;
- select * from student where marks>400;
(for students who got 400 or more)
- select * from student where marks >= 400;
(for students who got exactly 400 marks)
- select * from student where marks = 400;
# NUll
- empty value
(ifnull)
to replace "null" word with something else so user can understand...
pet table:
+----------+--------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+----------+--------+---------+------+------------+------------+
| Fluffy | Harold | cat | f | 1993-02-04 | NULL |
| Claws | Gwen | cat | m | 1994-03-17 | NULL |
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
| Fang | Benny | dog | m | 1990-08-27 | NULL |
| Bowser | Diane | dog | m | 1979-08-31 | 1995-07-29 |
| Chirpy | Gwen | bird | f | 1998-09-11 | NULL |
| Whistler | Gwen | bird | NULL | 1997-12-09 | NULL |
| Slim | Benny | snake | m | 1996-04-29 | NULL |
| Puffball | Diane | hamster | f | 1999-03-30 | NULL |
+----------+--------+---------+------+------------+------------+
# Where (continued)
- SYNTAX - select ..... from Table name WHERE column (condional operator) value;
e.g.
select * from student where gender = "M" and marks >= 300;
+-----------+------+--------+---------+-------+
| name | age | gender | matric | marks |
+-----------+------+--------+---------+-------+
| Abu Bakar | 15 | M | 9531185 | 456 |
| Zubin | 15 | M | 9531184 | 412 |
| Anup | 12 | M | 9531181 | 302 |
+-----------+------+--------+---------+-------+
#NOT
- Not True = False
- Not False = true
Q. select boys from student table who got more than 400 or 400 marks.
> select * from student where gender = "M" and marks >=400;
+-----------+------+--------+---------+-------+
| name | age | gender | matric | marks |
+-----------+------+--------+---------+-------+
| Abu Bakar | 15 | M | 9531185 | 456 |
| Zubin | 15 | M | 9531184 | 412 |
+-----------+------+--------+---------+-------+
> mysql> select * from pet where species = "dog" AND death <> "NULL";
+--------+-------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+--------+-------+---------+------+------------+------------+
| Bowser | Diane | dog | m | 1979-08-31 | 1995-07-29 |
+--------+-------+---------+------+------------+------------+
mysql> select * from pet where species = "dog" and death is not null;
+--------+-------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+--------+-------+---------+------+------------+------------+
| Bowser | Diane | dog | m | 1979-08-31 | 1995-07-29 |
+--------+-------+---------+------+------------+------------+
mysql> select * from pet where (species = "dog" or species = "cat") and sex = "m" ;
+--------+-------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+--------+-------+---------+------+------------+------------+
| Claws | Gwen | cat | m | 1994-03-17 | NULL |
| Fang | Benny | dog | m | 1990-08-27 | NULL |
| Bowser | Diane | dog | m | 1979-08-31 | 1995-07-29 |
+--------+-------+---------+------+------------+------------+
#SYMBOLIC REPRESNTATION
OR = ||
AND = &&
# NOT Operator
select * from pet where (species = "dog" or species = "cat") && sex = "m" ;
+--------+-------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+--------+-------+---------+------+------------+------------+
| Claws | Gwen | cat | m | 1994-03-17 | NULL |
| Fang | Benny | dog | m | 1990-08-27 | NULL |
| Bowser | Diane | dog | m | 1979-08-31 | 1995-07-29 |
+--------+-------+---------+------+------------+------------+
3 rows in set (0.00 sec)
mysql> select * from pet where not (species = "dog" or species = "cat") && sex =
"m" ;
+------+-------+---------+------+------------+-------+
| name | owner | species | sex | birth | death |
+------+-------+---------+------+------------+-------+
| Slim | Benny | snake | m | 1996-04-29 | NULL |
+------+-------+---------+------+------------+-------+