Skip to content

Commit 232225c

Browse files
committed
alter codes and create new study material
1 parent d6b918c commit 232225c

File tree

6 files changed

+216
-3
lines changed

6 files changed

+216
-3
lines changed

Leet code.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,50 @@
2020
# if a == str(x):
2121
# return True
2222
# else:
23-
# return False
23+
# return False
24+
25+
# class Solution:
26+
# def threeSum(nums, List):
27+
# res=[]
28+
# nums.sort()
29+
# length=len(nums)
30+
# for i in range(length-2):
31+
# if i>0 and nums[i]==nums[i-1]:
32+
# continue
33+
# l=i+1
34+
# r=length-1
35+
# while l<r:
36+
# total=nums[i]+nums[l]+nums[r]
37+
# if total<0:
38+
# l=l+1
39+
# elif total>0:
40+
# r=r-1
41+
# else:
42+
# res.append([nums[i],nums[l],nums[r]])
43+
# while l<r and nums[l]==nums[l+1]:
44+
# l=l+1
45+
# while l<r and nums[r]==nums[r-1]:
46+
# r=r-1
47+
# l=l+1
48+
# r=r-1
49+
# return res
50+
51+
52+
# import collections
53+
# def mindeletion(s):
54+
# deletion=0
55+
# freq=set()
56+
# charco=collections.Counter(s)
57+
# for chars,counts in charco.items():
58+
# while counts>0 and counts in freq:
59+
# counts-=1
60+
# deletion+=1
61+
# freq.add(counts)
62+
# return deletion
63+
64+
# a=input('enter: ')
65+
# result=mindeletion(a)
66+
# print(result)
67+
68+
69+

Python/firstclassfun.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# First class functions
2+
3+
# First class objects in a language are handled uniformly throughout.
4+
# They may be stored in data structures, passed as arguments, or used in control structures.
5+
# A programming language is said to support first-class functions if it treats functions as first-class objects.
6+
# Python supports the concept of First Class functions.
7+
8+
# Properties of first class functions:
9+
10+
# A function is an instance of the Object type.
11+
# You can store the function in a variable.
12+
# You can pass the function as a parameter to another function.
13+
# You can return the function from a function.
14+
# You can store them in data structures such as hash tables, lists, …
15+
16+
# Examples illustrating First Class functions in Python
17+
18+
# 1. Functions are objects:
19+
# Python functions are first class objects.
20+
21+
# Python program to illustrate functions
22+
# can be treated as objects
23+
def shout(text):
24+
return text.upper() # Print Uppercase
25+
26+
27+
print (shout('Hello')) # HELLO
28+
print(shout) # Print the object of the function
29+
yell = shout # assign a function to a variable and can be treated as objects
30+
print(yell) # print the object of the function shot and yell are same address yell -->shot
31+
print (yell('Hello')) # HELLO
32+
33+
# In the above program we are assigning function to a variable
34+
# This assignment doesn’t call the function. (yell=shot)
35+
# It takes the function object referenced by shout and creates a second name pointing to it, yell.(yell -->shot)
36+
37+
38+
# 2. Functions can be passed as arguments to other functions:
39+
# Because functions are objects we can pass them as arguments to other functions.
40+
# Functions that can accept other functions as arguments are also called higher-order functions.
41+

basic.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@
187187
# print()
188188
# space=space-1
189189

190+
191+
192+
190193
# Ratio of positive negative integer
191194
# def plusMinus(arr):
192195
# arr = [1, -2, 0, 3, -4]

list.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Problem Description
44
# Create a program to create a list of odd numbers from a list of numbers using list comprehension.
55
#
6-
# Create a list with the following data items 12, 17, 28, 19, 11, and assign it to the numbers variable.
6+
# 1. Create a list with the following data items 12, 17, 28, 19, 11, and assign it to the numbers variable.
77
# Create a new list and only print 17, 19, 11 (odd numbers) using list comprehension.
88
# Print newly created list.
99
# # Replace ___ with your code
@@ -14,7 +14,7 @@
1414
# # print new list
1515
# print(newlist)
1616
#
17-
# 2Natural Numbers List
17+
# 2 Natural Numbers List
1818
# Easy
1919
# Problem Description
2020
# Create a program to create a list of first n natural numbers using list comprehension.

listfunctions.py

Whitespace-only changes.

oops.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Variables
2+
a=10 # assign 10 to variable a
3+
b=10 # assign 10 to variable b
4+
5+
# id():
6+
# id() function is a built-in function that returns the unique identifier of an object.
7+
# The identifier is an integer, which represents the memory address of the object.
8+
# The id() function is commonly used to check if two variables or objects refer to the same memory location.
9+
print(id(a))#a and b have same value the memory location will be same displayed.
10+
print(id(b))
11+
12+
# class:
13+
# Python is an object oriented programming language.
14+
# Almost everything in Python is an object, with its properties and methods.
15+
# A Class is like an object constructor, or a "blueprint" for creating objects.
16+
# A class is a user-defined blueprint or prototype from which objects are created.
17+
# Classes provide a means of bundling data and functionality together.
18+
# Creating a new class creates a new type of object, allowing new instances of that type to be made.
19+
20+
class employee:
21+
# class is a keyword to create a class. class name is employee
22+
#if you create a empty class it shows an error so ypu need to put pass statement on it
23+
pass
24+
25+
emp1=employee()# each unique employee that we create using our employee class will be an instance of the class
26+
emp2=employee()
27+
print(emp1)# <__main__.employee object at 0x7fc5ca05bfd0> emp1 object memory address
28+
print(emp2)# <__main__.employee object at 0x7fc5ca05beb0> emp2 object memory address
29+
30+
31+
# object:
32+
# An object is called an instance of a class.here emp1 and emp2 have unique employee classes
33+
34+
35+
# pass:
36+
# The pass statement is used as a placeholder for future code.
37+
# When the pass statement is executed, nothing happens, but you avoid getting an error
38+
# when empty code is not allowed.
39+
# Empty code is not allowed in loops, function definitions, class definitions, or in if statements
40+
41+
42+
43+
class my_class:
44+
# global variable
45+
strength='empty'
46+
classroom='None'
47+
48+
def __init__(self,class_name="None",staff="Unallotted",fullname="None"):
49+
# self : Pointer to Current Object. staff=None is default arguments
50+
self.staff_name=staff # Instance variable creating automatically
51+
self.fullname=fullname
52+
self.classroom=class_name
53+
print(self.staff_name,self.fullname,self.classroom)
54+
55+
56+
def myclass(self,student): # without self keyword positional argument error occurs
57+
global strength # access the global variable change inside a function
58+
strength=student# it will work inside the
59+
return "Total strength of the class is " +strength # return statement store the value in the the function on it
60+
61+
def myfunct(self,repname):
62+
#local variable
63+
rep=repname
64+
print(self.classroom," incharge staff ",self.staff_name," full name ",self.fullname)
65+
print(rep+" is representative for " +self.classroom)
66+
print(self.strength+" students inside the class room ")
67+
#self.strength show class variable strength if current obj not available it will take global variable
68+
69+
70+
71+
72+
obj=my_class("I MCA","HPT","Harrish PT")
73+
# object creation for class (my_class is Class name).obj is instance of the class or object
74+
# you can't pass global variable inside class
75+
76+
# print(obj)
77+
# print memory address of the object (obj)
78+
79+
print(obj.strength)
80+
# Print obj.name is Global Variable (my_class.name)
81+
82+
obj.staff_name="KK"
83+
obj.fullname="Kishore"
84+
# Manually created instance variable
85+
86+
print("Manually created staff name : "+obj.staff_name)
87+
print("Manually created staff fullname : "+obj.fullname)
88+
# printing Manually created instance variable
89+
90+
print(obj.myclass('16'))
91+
# It will print inside the myfunc stored value //Roll16
92+
93+
obj.myclass('15')
94+
# It will not print anything if you call the function without print statement it will print Nothing
95+
96+
obj.myfunct('Harrish')
97+
# Here It will print the value because in myfunct contain print statement inside on it so no need to again use print function
98+
99+
obj2=my_class("I MCA",'Dk','Dineshkumar') # create a object and pass a value to the constructor or __init__ method
100+
obj2.myfunct('Santhosh')
101+
102+
# Instance variable:
103+
# Instance variable contains data that is unique to each instance.
104+
# Instance variable can created manually and automatically.
105+
# Manually set the variables every time its a lots of code and it also prone to mistake.
106+
107+
108+
# self
109+
# the term “self” refers to the instance of the class that is currently being used.
110+
# It is customary to use “self” as the first parameter in instance methods of a class.
111+
# Whenever you call a method of an object created from a class,
112+
# the object is automatically passed as the first argument using the “self” parameter.
113+
# The self is always pointing to the Current Object.
114+
# When you create an instance of a class,
115+
# you’re essentially creating an object with its own set of attributes and methods.
116+
117+
118+
# constructor
119+
# a class constructor is a special method named __init__ that gets called when you create an instance (object) of a class.
120+
# This method is used to initialize the attributes of the object.
121+
# Keep in mind that the self parameter in the constructor refers to the instance being created and allows
122+
# you to access and set its attributes.
123+

0 commit comments

Comments
 (0)