This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Employee: | |
| def __init__(self,name,age,exp,salary): ## Defining The Constructor With Common data | |
| ## Instance Attributes ## instance attributes that are only accessable by the object of the class | |
| self.name = name | |
| self.age = age | |
| self.exp = exp | |
| self.salary = salary | |
| def show(self): ## A Simple method that prints the data | |
| print(self.name,self.age,self.exp,self.salary) ## Printing all the variables |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Parent: ## Creating a class name Parent | |
| def __init__(self): ## Constructor of parent class | |
| # protected member | |
| self._mobilenumber = 5555551234 ## Protected member of the class Parent | |
| class Child(Parent): ## Child class inhering properties from the Parent class | |
| def __init__(self): ## Constructor of the class name | |
| Parent.__init__(self) ## accessing members of the Parent class, another way is to used supre() | |
| print("Calling Protected Member") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Rectangle: | |
| def __init__(self, l, b): | |
| self.l = l | |
| self.b = b | |
| def area(self): | |
| return self.l * self.b | |
| class Square: | |
| def __init__(self, side): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from abs import ABC, abstractmethod | |
| class Parent(ABC): | |
| @abstracmethod | |
| def show(self): | |
| pass | |
| class child(Parent): | |
| def show(self): | |
| print("Child Class") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import streamlit as st | |
| from textblob import TextBlob | |
| st.write(" Real Time Sentiment Analyzer ") | |
| input = st.text_input("Enter Your Review...") | |
| score = TextBlob(input).sentiment.polarity | |
| if score==0:st.write("Neutral π") | |
| elif score<0:st.write("Negative π«") | |
| elif score>0:st.write("Positive π") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import streamlit as st | |
| import nltk | |
| from nltk.sentiment.vader import SentimentIntensityAnalyzer | |
| nltk.download('vader_lexicon') | |
| st.write(" Real Time Sentiment Analyzer ") | |
| input = st.text_input("Enter Your Review...") | |
| score = SentimentIntensityAnalyzer().polarity_scores(input) | |
| if score==0: st.write("Neutral") | |
| elif score['neg']!=0: st.write("Negative") | |
| elif score['pos']!=0: st.write("Positive") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import scrapy | |
| class QuotesSpider(scrapy.Spider): | |
| name = "quotes" | |
| start_urls = [ # List of websites to scrape | |
| 'http://quotes.toscrape.com/' | |
| ] | |
| def parse(self, response): ## source code | |
| title = response.css('title::text').extract() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Elements Selector Expression | |
| All Tags (h1) response.css('h1').extract() | |
| All Tags with Id(Header) responses.css('#header::text').extract() | |
| All Links(a) response.css('a').extract() | |
| Extracting text from all the classes named text response.css('.text::text').extract() | |
| All Links(a) inside a Paragraph(p) tag response.css('p a::text').extract() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class GenerateSalary: | |
| ## Variable | |
| base_salary = 15000 | |
| ## Method | |
| def __init__(self,experience): | |
| self.experience = experience | |
| self.salary = self.base_salary*self.experience | |
| print(self.salary) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| Our task is to create a script that can scrape results from google based on some query. | |
| ''' | |
| from bs4 import BeautifulSoup | |
| import requests | |
| headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'} | |
| def google(query): | |
| query = query.replace(" ","+") | |
| try: | |
| url = f'https://www.google.com/search?q={query}&oq={query}&aqs=chrome..69i57j46j69i59j35i39j0j46j0l2.4948j0j7&sourceid=chrome&ie=UTF-8' |