diff --git a/.vscode/settings.json b/.vscode/settings.json index 5035f91..925a541 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,3 @@ { - "python.testing.pytestArgs": [ - "." - ], - "python.testing.unittestEnabled": false, - "python.testing.nosetestsEnabled": false, - "python.testing.pytestEnabled": true + "python.pythonPath": "C:\\Users\\Adnin\\AppData\\Local\\Programs\\Python\\Python38-32\\python.exe" } \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index f5ab210..0000000 --- a/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# Python practice set have many excersices to work on it and learn about python - -Python प्रैक्टिस सेट और बेसिक कान्सेप्ट के बारे मे बताया गया है। - -### प्रोफाइल और यूट्यूब चैनल को फॉलो और सबस्क्राइब जरूर करो। क्योंकि अभी काफी कुछ सीखना बाकी है। - -### मेरे Youtube चैनल को सबस्क्राइब करना ना भूलो ताकि आपको कोड का पूरा फ़्लो समझमे आए - [Hey Sushil YouTube Channel](https://www.youtube.com/channel/UCphs2JfmIClR62wbyf76HDg) - -### कोई भी सवाल है उसको मेरे यूट्यूब चैनल के कमेन्ट या डिस्कशन सेक्शन मे पूछ सकते हो - [Hey Sushil YouTube Discussion Point](https://www.youtube.com/channel/UCphs2JfmIClR62wbyf76HDg/discussion) - -### और हाँ GitHub पर मुझे फॉलो करना ना भूलो ताकि सारे अपडेट एण्ड वर्क आपको मिलता रहे। - -### पाइथान को और अच्छे से समझने के लिए [Hey Sushil YouTube](https://www.youtube.com/channel/UCphs2JfmIClR62wbyf76HDg) चैनल पर उपस्थित इन प्लेलिस्ट को देख सकते हो: - -1. [Full Python Course Video on Hey Sushil](https://www.youtube.com/playlist?list=PLK6wiPavf7QikS9PMYrGZXz1HlE1KZLD3) -1. [Numpy Array Video on Hey Sushil](https://www.youtube.com/playlist?list=PLK6wiPavf7QhptzzEb7ZuSoF7mPrT_m1a) -1. [Django Online Training on Hey Sushil](https://www.youtube.com/playlist?list=PLK6wiPavf7QjH9JNIYr18E2YgQxoFewL6) -1. [Python Project Video Playlist on Hey Sushil](https://www.youtube.com/playlist?list=PLK6wiPavf7Qj-NLJhbkxw9QfonweHafcN) -1. [Tips and Trics for Programming Video Playlist on Hey Sushil](https://www.youtube.com/playlist?list=PLK6wiPavf7QiVLYXrC2TW_fdcZp57MgMB) -1. [Python Online Class on Hey Sushil](https://www.youtube.com/playlist?list=PLK6wiPavf7QgnXqPf9jBEVr1iNUxiVoHG) -1. [PHP Project with Full Details and Source code on Hey Sushil](https://www.youtube.com/playlist?list=PLK6wiPavf7QiEj6IPc3lkjz1wR4w9RM6B) -1. [GitHub tutorials in Hindi on Hey Sushil](https://www.youtube.com/playlist?list=PLK6wiPavf7Qjydpc5v-hdIoqCx2V19pHP) -1. [Hey Kya karu main on Hey Sushil](https://www.youtube.com/playlist?list=PLK6wiPavf7QhMIbSQH56_qgtMvl30TSmj) - -### अगर टाइम हो तो हमारे सोशल मीडिया पेज को भी फॉलो कर सकते हो। - -1. [Twitter](http://twitter.com/heysushil) -1. [LinkedIn](https://www.linkedin.com/in/heysushil/) -1. [Facebook](https://www.facebook.com/heysusheel) -1. [Facebook Page](https://www.facebook.com/iheysushil/) - -### Other works and platforms: - -1. [Web Development](http://development.technokrits.com/) -1. [Tech Info](http://technokrits.com/) -1. [Technokrits YouTube](https://www.youtube.com/channel/UCiLCHj9Fw9iCS20mrvYgEKQ) - - diff --git a/__pycache__/constant.cpython-38.pyc b/__pycache__/constant.cpython-38.pyc new file mode 100644 index 0000000..492c67c Binary files /dev/null and b/__pycache__/constant.cpython-38.pyc differ diff --git a/__pycache__/json.cpython-38.pyc b/__pycache__/json.cpython-38.pyc new file mode 100644 index 0000000..d49fcc2 Binary files /dev/null and b/__pycache__/json.cpython-38.pyc differ diff --git a/__pycache__/module.cpython-38.pyc b/__pycache__/module.cpython-38.pyc deleted file mode 100644 index 98b00dd..0000000 Binary files a/__pycache__/module.cpython-38.pyc and /dev/null differ diff --git a/__pycache__/numpy.cpython-38.pyc b/__pycache__/numpy.cpython-38.pyc new file mode 100644 index 0000000..c5478de Binary files /dev/null and b/__pycache__/numpy.cpython-38.pyc differ diff --git a/basics.py b/basics.py new file mode 100644 index 0000000..61692cc --- /dev/null +++ b/basics.py @@ -0,0 +1,80 @@ +import constant + +print(constant.PI) +print ('hello pyhotn') +name = 'chaudhary' +print(name) +name = 'sushil' +print(name) +print +a = 5 +print(a, "is type of", type(a)) +a = 5.0 +print(a, "is type of", type(a)) +a = 1+2j +print(a, "is complex number? ", isinstance(a,int)) + +# list +a = [1,2,3,4,5,6,7,8,9] +a[1] = 3 +print('a[0:2] =',a) + +# tubles - this is same as list but it's non changeable but list values area changeable this is the diff +a = (1,2,3,4,5,6) +print(a) +print("values of a[2] is", a[2]) +# a[3] = 10 +# print(a[3]) + +# string +a = 'hello python' +print('sting value of a is',a) +print('value of stirng index a[2]', a[0:5]) +# a[0] = 'H' +# print('sring also immutable a[0]',a[0]) + +# set +# set are not accept +a = {1,2,3,4,5,'adf',1,2,3,4} +print('look the set',a) +# print('index of a[1]',a[1]) #index not allowed + +# directory +newdictonary = {'name':'sushil','address':'nirman vihar'} +print('value of newdirectory',newdictonary) +print(newdictonary['name']) +print(type(newdictonary)) + +# data type conversion +value = [1, 2, 3, 4, 5] +newconv = list(value) +newconv = tuple(value) +newconv = set(value) +value = ([[1,'hi'],[2,'hello']]) +newconv = dict(value) +# newconv = tuple({5,6,7}) +print('datatype',type(newconv)) +print(newconv) + +# fulll print syntex using dictoryny +details = {'name':'Sushil', + 'address':'Nirman vihar', + 'email':'sushil@g.com' + } +print('Hello {name}, Your Address is {address} and email id is {email} '.format( + name=details['name'], address=details['address'], email = details['email'])) + +# input +# inputnum = eval(input('Enter number: ')) +# print('Your entered number is = ',type(inputnum)) + +# modules breck the code on files and import them +from math import pi +print(pi) +ca = 12 +cb =15 +print('Rith or not:',ca<=cb) + + + +# on wp header.php at html tagdsddd diff --git a/class.py b/class.py index b8487c1..bdbef39 100644 --- a/class.py +++ b/class.py @@ -1,10 +1,42 @@ -class Person: - def __init__(self, name, age): - self.name = name - self.age = age +# class Person: +# def __init__(self, fname, lname, year): +# self.firstname = fname +# self.lastname = lname +# self.year = 2019 +# def printname(self): +# print('hello {} - {}'.format(self.firstname, self.lastname)) -p1 = Person("John", 36) -# p1.funcName(); -print(p1.name) -print(p1.age) +# #Use the Person class to create an object, and then execute the printname method: + +# # y = Person("John", "Doe") +# # y.printname() + + +# # child class +# class Student(Person): +# def __init__(self, fname, lname): +# self.year = 2019 +# super().__init__(self, fname, lname, year) #super class + +# def printvalue(self): +# print('hello') +# # print('Hello {}, and {} year {}'.format(self.firstname,self.lastname, self.year)) + +# x = Student("Mike", "Olsen") +# # x.printname() +# x.printvalue() + +import numpy +mytuple = ("apple", "banana", "cherry") +myit = iter(mytuple) + +print(next(myit)) +# print(next(myit)) +# print(next(myit)) + +speed = [99, 86, 87, 88, 111, 86, 103, 87, 94, 78, 77, 85, 86] + +x = numpy.median(speed) + +print(x) diff --git a/constant.py b/constant.py new file mode 100644 index 0000000..bf0ddec --- /dev/null +++ b/constant.py @@ -0,0 +1,2 @@ +PI = 3.14 +GRAVITY = 9.8 \ No newline at end of file diff --git a/datatype.py b/datatype.py deleted file mode 100644 index 069c401..0000000 --- a/datatype.py +++ /dev/null @@ -1,88 +0,0 @@ -demolist = [1,2,3,4,5,6,7] -# demolist.remove(1) -print(demolist.count(2)) -print(demolist[:]) -userdetail = [ - 'name','chaudhary suhsil', - 'email','sushil@gmail.com' -] -userdetail[0]='sushil' -userdetail.extend([1,2,3]) -# print(count(userdetail)) -print(userdetail) - -# pworser in case of lsit comparhension -pow2 = [2 ** x for x in range(10)] -print(pow2) - -# comperhansion list is awesome -newpow = [2 ** x for x in range(10) if(x> 5)] -print(newpow) - -# tuple -# this is called tuple packing -newtup = 3,4.6,'dog' -print(newtup) -# this tuple unpacking -a, b, c = newtup -print(a) -print(b) -print(c) - -# string -count = 0 -for letter in 'hello sushil': - if letter == 'l': - count += 1 -print(count,'letter found') -myname = 'sushil' -myname_enumarate = list(enumerate(myname)) -print(myname_enumarate) -print(len(myname)) -print('hello, "kyas haal hai"') - -# set are mutable and in between set also use all datatypes which are mutable -print(type({1,2,3,4,'hello'})) -print({1,2,3,4}) -myset = {'hello','hi','how','areyou'} -print(myset) -myset.add('sushil') -myset.update(['suraj','sunil']) -myset.discard('hi') -myset.remove('how') -print(myset) -# set use for performing mathematical operation -aset = {1,2,3,4,5} -bset = {5,6,7,8} -print('set union: ',aset|bset) -print('using unio function: ',aset.union(bset)) -print('intersion:',aset & bset) -print('using itersetion fun:',aset.intersection(bset)) -print('difference:',aset-bset) -print('deferencs fun:',aset.difference(bset)) -print('Sementric difference:',aset^bset) -print('semenmtric fun:',aset.symmetric_difference(bset)) -print('print in iteration using for:') -for letter in aset: - print('for loop:',letter) -print('frozen set') -afroz = frozenset([1,2,3,4,5]) -bfroz = frozenset([6,7,8,9]) -print('disjoint bothe:',afroz.isdisjoint(bfroz)) -print('diffrence in frozen:',afroz.difference(bfroz)) - -# dictonary -print('use of dictornay is same as set but its use key value and use curly backet') -adict = {'name': 'sushil','email':'sushil@gmail.com'} -adict['name'] = 'chaudhary sushil' -adict['mobile'] = '89899889' -print(adict.get('name')) -print(adict) -# print(adict.popitem()) -odddict = {x: x*x for x in range(6) if x % 2 == 1} -print({x: x*x for x in range(6) if x%2==1}) -print(odddict) -for i in odddict: - print('In interation:',odddict[i]) - - diff --git a/decorator.py b/decorator.py deleted file mode 100644 index 73f65cd..0000000 --- a/decorator.py +++ /dev/null @@ -1,53 +0,0 @@ -# decoratores are nothing more then assing value of variables. -# because in this case the decoratore means is to assign the calling function to a variable which holds that function on it. -# it also call as short hand the fucntion with define a new name to call same function by different name for different functions -# same case we done in class, when we have class so for using the class need to creat an object of it and we create as many as object as we want of the same class. -# in case of decoration same done by like class object -# short hand for the decorate is -''' - Exampele to shor hand way use of decoratoer - @make_pretty - def ordinary(): - print("I am ordinary") - is equivalent to - - def ordinary(): - print("I am ordinary") - ordinary = make_pretty(ordinary) - - --------------use of multiple decoratore------------- - Example: - def star(func): - def inner(*args, **kwargs): - print("*" * 30) - func(*args, **kwargs) - print("*" * 30) - return inner - - def percent(func): - def inner(*args, **kwargs): - print("%" * 30) - func(*args, **kwargs) - print("%" * 30) - return inner - - @star - @percent - def printer(msg): - print(msg) - printer("Hello") -''' - -def is_called(): - def is_returned(): - print("Hello") - return is_returned - - # def is_newmess(): - # print('Hello other sub functon') - # return is_newmess - -new = is_called() - -#Outputs "Hello" -new() diff --git a/demo.py b/demo.py deleted file mode 100644 index 1897ad6..0000000 --- a/demo.py +++ /dev/null @@ -1,72 +0,0 @@ -# print('Hello') -# a=3 -# if a <= 3: -# print('Value of a:',a) -# print('Hello next print') - -# # variables -# a = 'hello' -# a,b,c = 1,2,3 -# print(a) -# print(b) -# print(c) -# print(type(a)) - -# name = 'python' -# # print('Hello '+name) - -# # global var -# funname = 'hello python' #this is a global variable - -# def demofunction(): -# print(name) - -# demofunction() -# # a->b -# # array['sadfa','asdf','sdf'] -# # array[0] - -# # data type conversiton - -# a = '1' -# b = 1.0 -# print(a) -# print(type(b)) -# print(type(int(b))) - -import random - -print(random.randrange(2000,2005)) - -string = '''hello -hi -how are you''' -astirng = ' hello python ' -alist = ['hello','hi','how','are','you'] -print(alist[-1]) -print(astirng[-9]) -print(astirng.islower()) -print(astirng.replace('hello','hi')) -print(len(astirng)) -num = 46 -print('hell' in astirng) -print('Hello number+',num) -print('hello {0}, welcome to {1}'.format('Vanshika','Python')) -print("Hello \"New\" Python") -print(astirng.count('h')) -# print(type(astirng.translate)) - -avalue = 5 -b = 6 -# avalue += 7 -print('b value:',b) -print('SUm of avalue is:',avalue) -print(astirng.islower()) -if (not(avalue == 6)): - print('Get bothe value') -listval = [1, 2, 3, 4] -print(next(iter(int,listval))) -# print(next(iter(listval))) - -# for num in [1,2,3,4]: -# print(num) diff --git a/example/triangle.py b/example/triangle.py deleted file mode 100644 index e69de29..0000000 diff --git a/example_codes.py b/example_codes.py deleted file mode 100644 index 4929797..0000000 --- a/example_codes.py +++ /dev/null @@ -1 +0,0 @@ -# Relats examples of python diff --git a/exception.py b/exception.py deleted file mode 100644 index cb59816..0000000 --- a/exception.py +++ /dev/null @@ -1,42 +0,0 @@ -# sys use to get exceptions -import sys - -rendomList = ['a',0,2] - -for num in rendomList: - try: - print('Value print is: ',num) - r = 1/int(num) - break - except: - print('Oppss sys problem: ',sys.exc_info()[0],'occured') - print('Next entry') -print('The receprocal of',num,'is',r) - - -# create class -# parent class -class Birds: - - def __init__(self): - print('Bird is ready') - - def whoisThis(self): - print('Bird') - def swim(self): - print('Swim faster') - -# child class inherit parent calss Birds -class Piggen(Birds): - - def __init__(self): - # call super class - super.__init__() - print('Pegun is ready') - - def whoisThis(self): - print('Pegun is ready') - - - -print(Birds().whoisThis()) diff --git a/fdirectory.py b/fdirectory.py deleted file mode 100644 index 1d0366d..0000000 --- a/fdirectory.py +++ /dev/null @@ -1,36 +0,0 @@ -import os - -os.getcwd() -print(os.getcwdb()) -print(os.listdir()) -# print(check) -# print(os.mkdir('testdir')) -print(os.listdir()) -# os.mkdir('testdir') -# create file in directory -fname = open('testdir/text.txt', 'a') -fwrite = open('testdir/text.txt','w') -fwrite.write('Hello sushil how are you\nthis is firs directory inccer page') -# read the file -# fread = open('testdir/text.txt','r') -print(open('testdir/text.txt', 'r').read()) -# print(os.remove('testdir/text.txt')) - -# use shutil modul to delete non empty dierecoty -import shutil -shutil.rmtree('testdir') -# fname.write = 'hello sushil\nthis is a dmeo file which i just created ok.' -# print(fname.read()) -# print(os.rename('testdir','newtest')) -# print(os.rmdir('newtest')) -print(os.listdir()) - -def funcname(): - pass - -# function functionName(){ -# function body -# } -a = '1' -b = 1 -print(a) diff --git a/file.py b/file.py deleted file mode 100644 index fc79d63..0000000 --- a/file.py +++ /dev/null @@ -1,43 +0,0 @@ -print('File operations') -# f = open('file.txt') -# print('Is file open:',f) -# newf = open('hello.txt', mode='a') -# print('Create new file hello.txt:',newf) -# f.close() -# newf.close() - -# use safe mode avop mode is not safe on so use tye filan -try: - f = open('file.txt') - # best way to use the is - with - - with open('file.txt',mode='w') as f: - f.write('kya baat hai maza hi aa gaya. mast hai python hain na\n') - f.write('ye jo bate hai ye to hoti hi rangei\n\n') - f.write('magar agar kaha jaye to maja aata hai python me aur hai hi majedat') - # f.write('this is my first file\n') - # f.write('no problem to wirht here\n') - # f.write('it\'s great idea to writh in the file by python.\n\n') - # f.write('really awesome') - # with open('file.txt','r') as f: - # print(f) - - # newf = open('hello.txt',mode='a') - # print('created file:',f) - # print('Create new file using a:',newf) -finally: - f.close() - # newf.close() - -# read('file.txt') -readfile = open('file.txt','r') -print(open('file.txt', 'r').read()) -print('current file position:',readfile.tell()) -print('bright currsor to initial posion',readfile.seek(0)) - -# read file in loop -print('\n\n') -for i in readfile: - print(i,end='') #end use to stope reapeting double new line - -print(readfile.readline()) diff --git a/file.txt b/file.txt deleted file mode 100644 index fe07184..0000000 --- a/file.txt +++ /dev/null @@ -1,4 +0,0 @@ -kya baat hai maza hi aa gaya. mast hai python hain na -ye jo bate hai ye to hoti hi rangei - -magar agar kaha jaye to maja aata hai python me aur hai hi majedat \ No newline at end of file diff --git a/formodule.py b/formodule.py new file mode 100644 index 0000000..d77ddb2 --- /dev/null +++ b/formodule.py @@ -0,0 +1 @@ +# creating function diff --git a/function.py b/function.py deleted file mode 100644 index ae11818..0000000 --- a/function.py +++ /dev/null @@ -1,12 +0,0 @@ -def myfunc(n): - print('myfunb', n) -# print(a) - return lambda a: a * n - - -mydoubler = myfunc(2) -print(type(mydoubler)) -print(mydoubler(11)) - -hello = 1 -print(type(hello)) diff --git a/hello.txt b/hello.txt deleted file mode 100644 index e69de29..0000000 diff --git a/if.py b/if.py new file mode 100644 index 0000000..f66f128 --- /dev/null +++ b/if.py @@ -0,0 +1,24 @@ +a = 5 +name = 'Vanshika' +if a> 5: + print('Value of a: ',name) +# elif a>= 5: +# if name == 'Vaknshika': +# print('Hello - {0}, welcome to python'.format(name)) +# if a>= 5: +# print('Vlaue of a is {0}.'.format(a)) +else: + pass + # print('Not greate a') + + +a = 330 +b = 330 +print("A") if a> b else print("=") if a == b else print("B") +if a> b: + print("A") +else: + if a < b: + print("=") + else: + print("B") \ No newline at end of file diff --git a/ifelse.py b/ifelse.py deleted file mode 100644 index a49e650..0000000 --- a/ifelse.py +++ /dev/null @@ -1,11 +0,0 @@ -# if else stament - -# check negative or possitive case here -num = float(input('Enter your number:')) -if num>= 0: - if num>= 1: - print ('Num value is possitive') - else: - print('Value is zero') -else: - print ('Value is negative') diff --git a/json.py b/json.py new file mode 100644 index 0000000..6492950 --- /dev/null +++ b/json.py @@ -0,0 +1,13 @@ +import simplejson + +# some JSON: +x = '{ "name":"John", "age":30, "city":"New York"}' + +# parse x: +y = simplejson.loads(x) + +# the result is a Python dictionary: +print(y["age"]) + +print('Hello hi how are you') +# raise \ No newline at end of file diff --git a/list.py b/list.py deleted file mode 100644 index 6c33592..0000000 --- a/list.py +++ /dev/null @@ -1,97 +0,0 @@ -''' -Defference b/w list/tuple/set/dic - -list - - value changeable - dublicate values accept - ordered and indexed - syntex - [] -tupe - - value unchangeable - dublicate value accept - ordered and indexed - syntex - () - -set - - unordered aur unindexed - no dublicate value - syntex - {} - -dic - - unordered collection value - indexed - changeable - no dublicate - syntex - {} - --------------------------ABOUT INDEX POSSITIONS--------------------- -About - - index [] () {} - index postion - ex - [1] - negative index - ex - [-1] - last value posstion - range - [2:5] - default to range - [:5] - range stope point is 5 - to to last postion - [2:] - - negative rang - - -''' -# for loop -# i = 0 -# for(intialization;i <= 6;i++) -# { - # for loop body -# } - -# newlist = [1,2,3,4,5,6] -# for hello in newlist: -# print(hello) - -# # __len__ -# newvaribale = new ClassName() -# newvaribale.functionName() -# this -# self.newlist - -# function functionName(newFun()) - -def funcname(name): - print('Hello fun, I am',name) - -funcname('Python') #argument - -newlist = [1,2,3,4,5] -# newlist. -list1 = ["a", "b", "c"] -list2 = [1, 2, 3] - -for x in list2: - list1.append(x) - -print(list1) - -list1 = ["a", "b", "c"] -list2 = [1, 2, 3] - -# list1.extend(list2) -print(list1) - -list3 = list1+list2 -# list1. -print(list3) - -tupevalue = ('apple','kiwi','kiwi') -# x = list(tupevalue) -# x[1] = 'manago' -# print(x) -# print(tuple(x)) -print(tupevalue.count('apple')) - -thisset = {"apple", "banana", "cherry"} - -set2 = {"orange", "mango", "grapes","apple"} -print(thisset.union(set2)) -# print(thisset.discard('apple')) -# print(thisset) -# ans = thisset+set2 -# print(ans) diff --git a/loop.py b/loop.py deleted file mode 100644 index e3074bd..0000000 --- a/loop.py +++ /dev/null @@ -1,73 +0,0 @@ -# loop in python using 2 paremeters -# first is the variable which initialize before start -# second is the sequesnce in which the loop rounding -# like in py use a list,tuple,dictroney, string which provide many number of values - -# -------------------------------------------------------------------- -# ----------------FINAL ABOUT LOOP---------------------- -# ----------------------------------------------------------------------- -# loop is using only 2 parametres on loop case in for loop firs is the initialization value wich you can direct initialize here no need to initialize before and next the the way of how the loop itirate the same for the time . -# in this case on simple case on 2nd paremeter pass the list,dictonary,string value of repet the loop until not finish the value on these. -# on other side if we want to repeate the loop for same type of number like print 0 to 100 number in loop. In this casea py provides a range() predefine function which you also use direct without use of loop in just print case -# but on print case it use also if you want to use the sam ein case of loop then everything work same just change the second paremeter. -# like for initialize-value in list-value: -# in this case the list-value will use in range and in rage also use len-for get the length of the list to repect the loop untile get the end value -# in this case the for loop lookes like -# for i in range(len(itemsvalue)) - -# list of number -listnum = ['hello','hai','how','are','you'] -# print(len(listnum)) - -for i in range(len(listnum)): - print(listnum[i]) - -# print(list(range(0,10))) -# print(list(range(0,100))) -digit = [1,2,3] -for hello in digit: - print(hello) - # continue -else: - print('No item left') - -# ---------------------------------- -# WHILE LOOP -n = 10 -sum = 0 -i=1 -while i <= n: - sum = sum + i - # print(len(n)) - i = i+1 -print('get',sum) - -# whicle with else -counter = 0 -while counter < 3: - print('get counter') - counter = counter+1 -else: - print('stop counter') - -for val in 'string': - if val == 'i': - continue - print(val) - # break -else: - print('finshed string') - -# function -def simplefun(name): - return 'Hello, ' + name + ' how are you.' - # return - -print (simplefun('Roshan')) - -# lambda function -oldlist = [1,2,3,4,5,6,7,8,9] -newlist = list(map(lambda x: x*2, oldlist)) -print('New list is: ',newlist) - - diff --git a/loops.py b/loops.py deleted file mode 100644 index 17be2fe..0000000 --- a/loops.py +++ /dev/null @@ -1,87 +0,0 @@ -# intilization -# condition -# increment / decrement - -for i in range(5): - for j in range(i): - print(j) -print('\n') - -# for(intialization;condtion;increment) -# { -# //loop body -# } -# for i in range(1,11): -# for(i=0;i<8;i++) -# { -# //body -# } - -# intilization -# while(condtion) -# { -# //loop body -# increment / decreent -# } - -adj = ["red", "big", "tasty"] -fruits = ["apple", "banana", "cherry"] - -for x in adj: - for y in fruits: - print(x, y) - -# i is value initialization -# range or list or tupel or set or dict all are provide indexs or end point of loop -for i in range(-11,-1): - print(i) - -# num1 = int(input('Enmter fir number')) -# num2 = int(input('Enter second number')) -# print(type(num1)) -# print(type(num2)) -# sum = num1+num2 -# print(sum) -a = 1 -while a < 10: - print('A : ',a) - a = a+1 - -# with if -b = 10 -while b <= 20: - b += 1 # -- ++ - if b == 13: - continue - print('B is: ', b) -# decrement -dec = 20 -while dec> 0: - print('Dec value: ',dec) - dec = dec - 4 - -print('--------------------------') -mul1 = int(input('Enter number')) -mul = 1 -for mul in range(1,10, 2): - # print('Mul: ',mul1*mul) - print('Multip {0}'.format(mul1)) - mul += 1 -else: - print('{0} multiplication stop'.format(mul1)) - -num = 1 -while num> 5: - print('IN while loop') -else: - while num < 5: - print('Num: ',num) - num +=1 - -name = 'Vanshika' -print(name[1]) - -# for i in range(): - # pass -# while - diff --git a/module.py b/module.py deleted file mode 100644 index 12a0753..0000000 --- a/module.py +++ /dev/null @@ -1,4 +0,0 @@ -def sumOfTwo(num1, num2): - # print(num1 + ' and ' + num2 ) - result = num1 + num2 - return result diff --git a/module1.py b/module1.py deleted file mode 100644 index 0c4894a..0000000 --- a/module1.py +++ /dev/null @@ -1,19 +0,0 @@ -import module -print(module.sumOfTwo(12,12)) -import math -# print(dir(math)) -# import math as m -from math import pi as p, e as u -print(p) -print(type(p)) -c = 8 + 7j -type(c) -print(isinstance(c, complex)) -print((1.1+2.2) != 3.3) -# print(u) -print(math.cos(math.pi)) -print(math.factorial(30)) -print(math.cos(p)) -print(math.pow(2,3)) -# import sys -# print(sys.path) diff --git a/mysql_example/data.py b/mysql_example/data.py new file mode 100644 index 0000000..c991084 --- /dev/null +++ b/mysql_example/data.py @@ -0,0 +1,24 @@ +import mysql.connector as mysql + +mydb = mysql.connect( + host='localhost', + user='root', + password='', + database='pythondemo' +) +# print(mydb) + +# create db +mycursor = mydb.cursor() +mycursor.execute('CREATE DATABASE IF NOT EXISTS pythondemo') +mycursor.execute('CREATE TABLE IF NOT EXISTS user(id int(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, name varchar(100))') +# mycursor.execute('SHOW DATABASES') + +# for x in mycursor: +# print(x) +# query = 'INSERT INTO user(name) VALUES("Sushil")'; +name = [('Himanshu'),('Muskan'),('Saini'),('Sanjay'),('Gaurav')] +mycursor.executemany('INSERT INTO user(name) VALUES("%s")', (name)) +mydb.commit() +print(mycursor.rowcount, "Recored inserted") +# mydb.close() diff --git a/namespace.py b/namespace.py deleted file mode 100644 index 92f62a8..0000000 --- a/namespace.py +++ /dev/null @@ -1,30 +0,0 @@ -# namespace practice -#checkign or teshing only -#what to do - -def outer_function(): - a = 20 - def inner_function(): - a = 30 - print('inernal a=',a) - - inner_function() - print('normal inner a=',a) - -a = 10 -outer_function() -print('outer a=',a) - -# next same function with global -def outer_again(): - global a - a = 30 - def inner_again(): - global a - a=900 - print('Again inner fun',a) - inner_again() - print('Again out a',a) -a = 10 -outer_again() -print('outer noramla a',a) \ No newline at end of file diff --git a/numpy.py b/numpy.py new file mode 100644 index 0000000..899b849 --- /dev/null +++ b/numpy.py @@ -0,0 +1,6 @@ +import re + +s = "Replaces one or many matches with a string orajskhdfklorljsdhflorjksdhfklaorjasdfklorjsdfhlkor" + +print(re.split("or",s)) + diff --git a/properti.py b/properti.py deleted file mode 100644 index 772d148..0000000 --- a/properti.py +++ /dev/null @@ -1,25 +0,0 @@ -# property is @ -class Celsius: - def __init__(self, temperature=0): - # self.temperature = temperature - # assing the temperature the the set fucntion - self.set_temperature(temperature) - - def to_fahrenheit(self): - return (self.get_temperature() * 1.8) + 32 - - def get_temperature(self): - return self._temperature - - def set_temperature(self, value): - if value < -273: - raise ValueError('Temperature below -273 not possible') - self._temperature = value - -# create object of class -man = Celsius() -# assign value to temperature -man.temperature = 6 -print(man.temperature) -# call the to_fahrenheit function -print('Degree: ',man.to_fahrenheit()) \ No newline at end of file diff --git a/python_practice.code-workspace b/python_practice.code-workspace new file mode 100644 index 0000000..815e6fb --- /dev/null +++ b/python_practice.code-workspace @@ -0,0 +1,9 @@ +{ + "folders": [ + { + "name": "python_practice", + "path": "." + } + ], + "settings": {} +} \ No newline at end of file diff --git a/regex.py b/regex.py deleted file mode 100644 index bccf89c..0000000 --- a/regex.py +++ /dev/null @@ -1,144 +0,0 @@ -# regex using module re to match patterns - -''' -MetaCharacters -Metacharacters are characters that are interpreted in a special way by a RegEx engine. Here's a list of metacharacters: - -[] . ^ $ * + ? {} () \ | - -Here, [abc] will match if the string you are trying to match contains any of the a, b or c. - -You can also specify a range of characters using - inside square brackets. - -[a-e] is the same as [abcde]. -[1-4] is the same as [1234]. -[0-39] is the same as [01239]. - -You can complement (invert) the character set by using caret ^ symbol at the start of a square-bracket. - -[^abc] means any character except a or b or c. -[^0-9] means any non-digit character. - -. - Period - -A period matches any single character (except newline '\n'). - -^ - Caret - -The caret symbol ^ is used to check if a string starts with a certain character. - -$ - Dollar - -The dollar symbol $ is used to check if a string ends with a certain character. - -* - Star - -The star symbol * matches zero or more occurrences of the pattern left to it. - -+ - Plus - -The plus symbol + matches one or more occurrences of the pattern left to it. - -? - Question Mark - -The question mark symbol ? matches zero or one occurrence of the pattern left to it. - -{} - Braces - -Consider this code: {n,m}. This means at least n, and at most m repetitions of the pattern left to it. - -| - Alternation - -Vertical bar | is used for alternation (or operator). - -() - Group - -Parentheses () is used to group sub-patterns. For example, (a|b|c)xz match any string that matches either a or b or c followed by xz - -\ - Backslash - -Backlash \ is used to escape various characters including all metacharacters. For example, - -\$a match if a string contains $ followed by a. Here, $ is not interpreted by a RegEx engine in a special way. - -If you are unsure if a character has special meaning or not, you can put \ in front of it. This makes sure the character is not treated in a special way. - -''' - -''' -----------------Special Sequences-------------------------- -Special sequences make commonly used patterns easier to write. Here's a list of special sequences: - -\A - Matches if the specified characters are at the start of a string. - -\b - Matches if the specified characters are at the beginning or end of a word. - -\B - Opposite of \b. Matches if the specified characters are not at the beginning or end of a word. - -\d - Matches any decimal digit. Equivalent to [0-9] - -\D - Matches any non-decimal digit. Equivalent to [^0-9] - -\s - Matches where a string contains any whitespace character. Equivalent to [ \t\n\r\f\v]. - -\S - Matches where a string contains any non-whitespace character. Equivalent to [^ \t\n\r\f\v]. - -\w - Matches any alphanumeric character (digits and alphabets). Equivalent to [a-zA-Z0-9_]. By the way, underscore _ is also considered an alphanumeric character. - -\W - Matches any non-alphanumeric character. Equivalent to [^a-zA-Z0-9_] - -\Z - Matches if the specified characters are at the end of a string. - -Tip: To build and test regular expressions, you can use RegEx tester tools such as regex101. This tool not only helps you in creating regular expressions, but it also helps you learn it. - -Now you understand the basics of RegEx, let's discuss how to use RegEx in your Python code. -''' -import re -pattern = '^a...s$' -test_string = 'abyss' -result = re.match(pattern,test_string) -print(result) -if result: - print('Pattern matched') -else: - print('Pattern not matched') - -# use findall -p = '\d+' -s = 'hello 34 sushil 45 how 55' -result = re.findall(p,s) -print(result) - -''' -re.split() -The re.split method splits the string where there is a match and returns a list of strings where the splits have occurred. - -''' - -string = 'Twelve:12 Eighty nine:89.' -pattern = '\d+' - -result = re.split(pattern, string) -print(result) - -# Output: ['Twelve:', ' Eighty nine:', '.'] - -''' -You can pass maxsplit argument to the re.split() method. It's the maximum number of splits that will occur. -''' - -string = 'Twelve:12 Eighty nine:89 Nine:9.' -pattern = '\d+' - -# maxsplit = 1 -# split only at the first occurrence -result = re.split(pattern, string, 1) -print(result) - -# Output: ['Twelve:', ' Eighty nine:89 Nine:9.'] -# By the way, the default value of maxsplit is 0 -# meaning all possible splits. - -# ---------------------------------------------- -# In vs code after adding re. get all sujessions on list which helps to understand the related sub functions on it -# ---------------------------------------------- \ No newline at end of file diff --git a/testdir/text.txt b/testdir/text.txt deleted file mode 100644 index 4aedcbf..0000000 --- a/testdir/text.txt +++ /dev/null @@ -1,2 +0,0 @@ -Hello sushil how are you -this is firs directory inccer page \ No newline at end of file diff --git a/text.txt b/text.txt deleted file mode 100644 index e69de29..0000000