Skip to content

Instantly share code, notes, and snippets.

View Abhayparashar31's full-sized avatar
:octocat:
Learning New Things

Abhay Parashar Abhayparashar31

:octocat:
Learning New Things
View GitHub Profile
def check(numbers):
for i in numbers:
if i == 0:
print("0 is present")
else:
print("0 is not present")
check([1,2,3,4]) ### 0 not present
check([0,1,2]) ## 0 present
numbers = [1,2,3,4,5]
fSet = frozenset(numbers)
print('frozen set:', fSet)
>> frozen set: frozenset({1, 2, 3, 4, 5})
fSet.add('8')
>>AttributeError: 'frozenset' object has no attribute 'add'
import speech_recognition as sr
def command():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Alexa: Listening...")
audio=r.listen(source)
try:
query = r.recognize_google(audio)
print(f"master:{query}")
return query
import pyttsx3
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
## speak("Don't Buy Alexa! Build Your Own Using Python") ## uncomment this to test the function
import pyttsx3
import speech_recognition as sr
import wikipedia
import pyjokes
import random
import requests
import datetime
import os
lst = [1,2,3,4,5,6,7,8,9,10] ## iterable object
def even_or_odd(num): ## Function to check even and odd
if num%2==0:
return "even"
else:
return "odd"
list(map(even_or_odd,lst)) ## using map we are applying the function to each element of the ierable which will check whether the element is even or odd
-----------------------------------------
['odd', 'even', 'odd', 'even', 'odd', 'even', 'odd', 'even', 'odd', 'even']
class add:
def __init__(self,a,b):
self.a = a
self.b = b
def add(self):
print(self.a+self.b)
class sub(add):
def __init(self):
super().__init()
super().__init()
from abc import ABC, abstractmethod
class Fruit(ABC):
# abstract method
def noofsides(self):
pass
class Orange(Polygon):
# overriding abstract method
def method(self):
print("I am Juicy")
class Computer:
def __init__(self):
self.__maxprice = 800
def sell(self):
print("Selling Price: {}".format(self.__maxprice))
def setMaxPrice(self, price):
self.__maxprice = price
Python is an interpreted, high level and general purpose programming language.
Python's design philosophy emphasizes code readability with its notable use of significant whitespace.
Its language constructs and object oriented approach aim to help programmers write clear,
logical code for small and large-scale projects.[28]
Python is dynamically typed and garbage collected.
It supports multiple programming paradigms, including structured ( particularly procedural ) object oriented,
and functional programming. Python is often described as a "batteries included" language due to its comprehensive standard library.
Python was created in the late 1980s, and first released in 1991,
by Guido van Rossum as a successor to the ABC programming language. Python 2.0, released in 2000,
introduced new features, such as list comprehensions and a garbage collection system with reference counting,