Posts

SQL Aggregate functions and Joins

 select count(*) from Customers; select avg(age) from Customers; select sum(age) from Customers; select min(age) from Customers; select max(age) from Customers; select Customers.first_name,Customers.last_name,Orders.item,Orders.amount from Customers inner join Orders on Customers.customer_id=Orders.customer_id; select Customers.first_name,Customers.last_name,Orders.item,Orders.amount from Customers left join Orders on Customers.customer_id=Orders.customer_id; select Customers.first_name,Customers.last_name,Orders.item,Orders.amount from Customers right join Orders on Customers.customer_id=Orders.customer_id; select Customers.first_name,Customers.last_name,Orders.item,Orders.amount from Customers full join Orders on Customers.customer_id=Orders.customer_id;

Conditionals, Loops, Break and Continue

 // Online C++ compiler to run C++ program online #include <iostream> using namespace std; int main() {     // Write C++ code here     // int a;     // cout<<"Enter the value for a"<<endl;     // cin>>a;     // if(a<23){     //     if(a==12){     //         cout<<"Entered 12"<<endl;     //     }     //     else if(a<10){     //         cout<<"Less than 10"<<endl;     //     }     //     else{     //         cout<<"A is greter than 10 or 12"<<endl;     //     }     // }     // else{     //     cout<<"A is greater than 23"<<endl;     // }    ...

Regular Expressions

 import re s="Python is am awesome cat car cam dog and a snake 27  30" # res=re.findall("Python",s) # Finds all the string which is a match # res=re.findall("c.t",s) # res=re.findall("ca.",s) # res=re.search("Python",s) # searches and returns a an object # res=re.match("Python",s) # res=re.findall(r"\d+",s) # used regex for finding numbers # res=re.findall("[0-9]",s) # numbers # res=re.findall("^Py",s) # starts with # res=re.findall("30$",s) #Ends with # res=re.findall("[A-Z]|[0-9]",s) # '|' used for OR condition # res=re.findall("[a-zA-Z]",s) # Multiple ranges # res=re.findall("[^0-9]",s) # ^ used in the front to denote not a digit res=re.findall("[0-9]",s) print(res)

List Comprehension

  # f=open("filo.txt","a+") # # f.write("Hello, this is a test file.\n") # a=f.read() # print(a) # f.close() # with open("filo.txt", "r") as f: #     a=f.read() #     print(a) # li=[x*x for x in range(1,11)] li = [ x for x in range ( 11 ) if x % 2 == 0 ] print ( li )

Decorators

 def fun(fu):     def pun():         print("Hit")         fu()         print("Kick")     return pun           @fun def greet():     print("Hi their")      greet() def fury(*a):     for i in a:         print(i)          def funy(**a):     for i,v in a.items():         print(f"{i} = {v}",end="\n") funy(s1="Gunjan",s2="Nayak",s3=25)          fury(1,2,3)

Python Time Zones

  from datetime import datetime from zoneinfo import ZoneInfo # UTC=Coordinated Universal Time date = datetime . now ( ZoneInfo ( "UTC" )) india_time = date . astimezone ( ZoneInfo ( "Asia/Kolkata" )) usa_time = datetime . now ( ZoneInfo ( "America/New_York" )) uk_time = datetime . now ( ZoneInfo ( "Europe/London" )) japan_time = datetime . now ( ZoneInfo ( "Asia/Tokyo" )) australia_time = datetime . now ( ZoneInfo ( "Australia/Sydney" )) germany_time = datetime . now ( ZoneInfo ( "Europe/Berlin" )) print ( usa_time ) print ( india_time ) print ( uk_time ) print ( japan_time ) print ( australia_time ) print ( germany_time ) # print(date)

Python Datetime Module

 import datetime x=datetime.datetime.now() print(x) print(x.year) print(x.strftime("%A")) print(x.strftime("%B")) print(x.strftime("%C")) print(x.strftime("%D")) print(x.strftime("%a")) print(x.strftime("%w")) print(x.strftime("%d")) print(x.strftime("%b")) print(x.strftime("%m")) print(x.strftime("%y")) print(x.strftime("%Y")) print(x.strftime("%H")) print(x.strftime("%I")) print(x.strftime("%p")) print(x.strftime("%M")) print(x.strftime("%S")) print(x.strftime("%f")) print(x.strftime("%Z")) print(x.strftime("%z")) print(x.strftime("%j")) print(x.strftime("%U")) print(x.strftime("%W")) print(x.strftime("%c")) print(x.strftime("%C")) print(x.strftime("%x")) print(x.strftime("%X")) print(x.strftime("%%")) print(x.strftime...