Академический Документы
Профессиональный Документы
Культура Документы
type(a)
% remainder
**exponent
z= a+bj
z.real=a
z.imag=b
list:
z =[a,b,c,d,g,f]
to change value of list:
a[2]=x
z=[a,b,x,d,g,f]
tuple:
a=(1,2.3,4,5)
floor division:
15//4=3 and not 3.75
modulus:
7.2%3=1.2 (remainder)
equality:
a==b
suppose:
a=7.8
then,
int(7.8)=7
float(7.8)=7.8
complex(7.8)=7.8+0j
str(7.8)="7.8"
print(name)
if statements:
eg:
ch=1
count=0
if ch<=8:
ch+=1
count+=1
if else:
a=int(input("enter a number'))
if a>=0:
print("a is positive")
else:
print("a is negative")
if-elif:
if(conditional)
statement
elif(conditional)
statement
else(conditional)
statement
a in range()
a not in range()
for loop:
for a in sequence
statements to repeat
while loop:
eg:
while (logical expression)
statements
string slices
name[n:m:step value]
to create a list:
a=list[value]
len(a) gives the length of the list
a[n:m:step value]
List commands:
say L=[1,2,3,4,5]
1) L.apprend(item), adds an item at the end of a list
2) L[index]=new value, adds an item at the respective indexes
3)del L[index]=deletes the value at the respective index in the list
4)L.pop(index)=deletes the vlaue at the respecive index AND shows the value
deleted, if no index specified it will remove last value
5)L.index(value)=returns the index of the value from the list
6)say L2=[6,7], then L.extend(L2) is [1,2,3,4,5,6, 7]
7)L.insert[index,value]= Inserts a new value at its dedicated position
8)L.clear()=erases the list
9)L.count(value)=counts the number of occurences of that specific value
10)L.reverse()=reverses items of the list
11)L.sort()=sorts the items of list in ascending order
L.sort(reverse=true) for descending order
Dicitionaries:
Dictionary name={key:value,key:value,key:value..n.}...note key has to be of
immutable type (cannot be a list)
say d={1: "a" , 2: "b" , "a":"c"}
d[1]="a"
eg: for key in d:
print(key ":" d[key])
d.keys()=prints all the keys of the dictionary
d.value()=prints all the values
d[key]=value, a new record is added or changed
Dictionary commands:
1)del d[key]
2)d.pop[key], d.pop(key, if key not present then message to show)
3)key in d, k not in d, checking for presence
4)json.dumps(d,indent=n)
5)len(d)
6)clear(d)
7)d.get(key, message to show if key does not exist)
8)say d2={1: "f",2: "k", 3= "g"} then d.update(d2)= {"a":"c",1: "f",2: "k", 3=
"g"}, the data present in d has been overriden by d2, notice the order of keys have
changed...no order is specifies in dictionary
Transfering files:
1) To read data from a csv file into the dataframe:
DF=pandas.read_csv(File path, name=[column names], header=none, skiprows=<n>,
nrows=number of rows to display, sep=<any character that you want to appear bw each
feild>)
name=[column names] allows you to give the name of columns a sper your choice
header=none has no column name
nrows=x allows you choose how many rows to display
sep="," will show a comma bw each feild in a record....denmark ; peru ; beat
Commands of mysql
Create database <name>;
use <name>;
select <column names> from tablename;
select* from table name;
select distinct <column name> from tablename; #does not give repeated records
show tables;
desc or describe<tablename> ;
to perform calculations:
select a+b;
select a*b;
putting text to appear in every row: select salesman_name, "gets the comission",
comm*100,"%" <=== here gets the commission and % appears in every row
Where clause:
select<columname> from tablename where <condition>
Databases:
Create database name;
show databases;
drop database <name>;
Tables:
Create table (table name)
(column name datatype(size) column constraints
);
Constraints:
Unique: makes sure that all the values in that column are unique, allows null value
primary key: it declares the column as primary key
default "value": it specifies a value automatically for that column when no value
is entered
check (conditional) : limits values that can be entered in the column
Foreign Key constraint=> columname datatype(size) References tablename (columname)
[ON UPDATE CASCADE][ON DELETE CASCADE]
OR you can create a constraint=> constraint<name-of-constraint><definition of
constraint>
DML commands:
-insert into <tablename> (column list)
-values(values as per subtending column list)
-eq: insert into branch1
select*from branch2
where gross>7000
-commit; to make changes permanent
-update:
update items
set rol=400
where rol=300;
-delete from <tablename>
[where=conditional]===> if where not included then it will empyt whole table
DDL commands:
-Alter table <tablename>
add <columname><datatype><size>constraint..etc.
-Alter table <tablename>
modify (columname newdatatype (newsize)[First/after column]==>to specify postion
of column
-Alter table <tablename>
change <old columname> <new columname> datatype....
-Alter table <tablename>
drop primary key, drop foreign key <constraint name>, drop <columname>