Skip to content

Commit ed5eaed

Browse files
authored
Add files via upload
1 parent e1a79c9 commit ed5eaed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1764
-0
lines changed

Advance_function.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'''
2+
author : Jaydatt
3+
Advance function : optional parameter and keyword parameter
4+
'''
5+
6+
print("------Optional Parameters--1-----: ")
7+
def add(v1=0,v2=0,v3=0):
8+
return (v1+v2+v3)
9+
10+
print(add())
11+
print(add(1))
12+
print(add(1,2))
13+
print(add(1,2,3))
14+
15+
16+
print("------Optional Parameters--2-----: ")
17+
def fun(x = 1, y = 2, z = 3):
18+
return("X={} ; Y={} ; Z={}".format(x,y,z))
19+
20+
print("fun() : ",fun())
21+
print("fun(1) : ",fun(1))
22+
print("fun(1,2) : ",fun(1,2))
23+
print("fun(1,2,3) : ",fun(1,2,3))
24+
25+
print("fun(x = 10) : ",fun(x=10))
26+
print("fun(y = 20) : ",fun(y=20))
27+
print("fun(z = 30) : ",fun(z=30))
28+
29+
print("fun(x = 10,y = 20) : ",fun(x=10,y = 20))
30+
print("fun(y = 20,z = 30) : ",fun(y=20,z = 30))
31+
print("fun(z = 30,x = 10) : ",fun(z = 30,x = 10))
32+
33+
print("fun(x = 10,y = 20,z = 30) : ",fun(x = 10,y = 20,z = 30))
34+
print("fun(y = 20,x = 10,z = 30) : ",fun(y = 20,x = 10,z = 30))
35+
print("fun(z = 30,y = 20,x = 10) : ",fun(z = 30,y = 20,x = 10))
36+
37+
38+
print("------Optional Parameters--3-----: ")
39+
print(int("100"))
40+
print(int("100", 10)) # same thing, 10 is the default value for the base
41+
print(int("100", 8)) # now the base is 8, so the result is 1*64 = 64
42+
43+
print("------Optional Parameters--4-----: ")
44+
def addList(val = "NA", lst = []):
45+
lst.append(val)
46+
return lst
47+
48+
print(addList())
49+
print(addList(1))
50+
print(addList("Py"))
51+
print(addList(2))
52+
print(addList(4, []))
53+
print(addList(5, ["Hello"]))

Booleans.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'''
2+
author : Jaydatt
3+
Booleans
4+
'''
5+
6+
print(True)
7+
print(False)
8+
print(type(True))
9+
print(type(False))

Condition.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
2+
'''
3+
author : Jaydatt
4+
In if-elif-else ladder elif and else are optional it is not mandatory.
5+
syntax :
6+
if(expression):
7+
statements......
8+
..........
9+
elif(expression):
10+
statements......
11+
..........
12+
else:
13+
statements......
14+
..........
15+
16+
Expression: boolean (<,>,<=,>=,==,!=,&,|,in,is,and,or)
17+
18+
'''
19+
20+
21+
22+
op = int(input('enter value of op(0,1,-1):'))
23+
if(op==0):
24+
print("no")
25+
elif(op>0):
26+
print("yes")
27+
else:
28+
print("I am optional")
29+
30+
31+
## find given name is present or not in list
32+
names = ["amit", "shubham", "rohit", "rohan", "aditi", "shipra"]
33+
name = input("Enter the name to check\n")
34+
35+
if name in names:
36+
print("Your name is present in the list")
37+
else:
38+
print("Your name is not present in the list")
39+
40+
# if else using "is"
41+
c = int(input("enter 0 or 1:"))
42+
print(c is 0)
43+
if (c is 0):
44+
print("zero")
45+
else:
46+
print("one")
47+
48+
# if else using "in"
49+
l1 = [45, 56, 6]
50+
d = int(input("enter any(45,56,6):"))
51+
print(d in l1)
52+
if (d in l1):
53+
print("yes")
54+
else:
55+
print("no")
56+
57+
## age compare sample
58+
age = int(input("Enter your age: "))
59+
60+
if(age>18 and age<56):
61+
print("You can work with us")
62+
else:
63+
print("You cannot work with us")
64+
65+
if(age>34 or age<50):
66+
print("ok")
67+
else:
68+
print("not ok")
69+
70+
## spam comment is defined as text containg keywords:"make a lot of money","buy now","click this","subscribe this"
71+
text = input("Enter the text\n")
72+
73+
if("make a lot of money" in text):
74+
spam = True
75+
elif("buy now" in text):
76+
spam = True
77+
elif("click this" in text):
78+
spam = True
79+
elif("subscribe this" in text):
80+
spam = True
81+
else:
82+
spam = False
83+
84+
if(spam):
85+
print("This text is spam")
86+
else:
87+
print("This text is not spam")
88+
89+

Count_and_Index.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'''
2+
author : Jaydatt
3+
count is used to count hom many time word is used
4+
index is used to find index number of matching word
5+
6+
count : The first method we'll talk about is called count. It requires that you provide one argument, which is what you would like to count. The method then returns the number of times that the argument occured in the string/list the method was used on. There are some differences between count for strings and count for lists. When you use count on a string, the argument can only be a string.
7+
8+
index: The other method that can be helpful for both strings and lists is the index method. The index method requires one argument, and, like the count method, it takes only strings when index is used on strings, and any type when it is used on lists. For both strings and lists, index returns the leftmost index where the argument is found. If it is unable to find the argument in the string or list, then an error will occur.
9+
'''
10+
string = 'Welcome to python'
11+
list = ['aa','bb','cc','dd', [] ]
12+
tuple = (1, 2, 5, 3, 6, 4, 7, 2 ,2)
13+
14+
print("string.count('x') : ", string.count('x'))
15+
print("list.count('jj') : ", list.count('jj'))
16+
print("tuple.count(11) : ", tuple.count(11))
17+
18+
print("string.count('e') : ", string.count('e'))
19+
print("list.count('bb') : ", list.count('bb'))
20+
print("tuple.count(2) : ", tuple.count(2))
21+
22+
print("string.index('p') : ", string.index('p'))
23+
print("list.index('cc') : ", list.index('cc'))
24+
print("list.index([]) : ", list.index([]))
25+
print("tuple.index(6) : ", tuple.index(6))
26+
27+
# error if word not match
28+
# Error : print("string.index('x') : ", string.index('x'))
29+
# Error : print("list.index('jj') : ", list.index('jj'))
30+
# Error : print("tuple.index(11) : ", tuple.index(11))
31+
32+
set = {'AA','BB','CC','DD'}
33+
# error: print(set.count('AA')) not applicable for set

Dictionary.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'''
2+
author : Jaydatt
3+
dictionary
4+
'''
5+
dic = {
6+
"Name": "Rahul",
7+
"Gender": "Male",
8+
"Contacts": {"Mobile": 5646845 , "Email" : "xyz@abc"},
9+
"Address": {"Country":"India","State":"Mumbai"},
10+
1: 2}
11+
12+
dic["Age"] = 21 # add or modify value of key
13+
dic['Marks'] = "85%" # add or modify value of key
14+
15+
del dic['Marks'] # delete Marks key and its value
16+
del dic ['Address']['State'] # delete State key and its value
17+
18+
print("----------")
19+
for key in dic : ## or for key in list(dic.keys()) :
20+
print( key,": ", dic[key])
21+
print("----------")
22+
23+
# The difference between .get(key) and [key] sytax in Dictionaries?
24+
# if key found then returns value of key, otherwise return None
25+
print("dic.get('Name') : ", dic.get('Name'))
26+
# if key found then returns value of key, otherwise throws error
27+
print("dic['Name'] : ", dic['Name'])
28+
29+
print("dic['Age'] : ",dic['Age'])
30+
print("dic['Contacts']['Email'] : ", dic['Contacts']['Email'])
31+
32+
print("----------list(dic.keys()) : \n", list(dic.keys())) # Prints the keys of the dictionary
33+
print("----------list(dic.values()) : \n", list(dic.values())) # Prints the values of the dictionary
34+
print("----------list(dic.items()) : \n", list(dic.items())) # Prints the (key, value) for all contents of the dictionary
35+
36+
print("----------dic: \n",dic)
37+
38+
dic_2 = {
39+
"Lovish": "Friend",
40+
"Divya": "Friend",
41+
"Shubham": "Friend",
42+
"rahul": "A Dancer"}
43+
# Updates the dictionary by adding key-value pairs from updateDict
44+
dic.update(dic_2)
45+
46+
print("----------dic: \n",dic)
47+
48+
'''
49+
we can not take list in set and error generate for example:
50+
s = {8,7,"Amit",[5,6]}
51+
52+
we can take tupel in set but can not modify tupel for example:
53+
s = {8,7,"Amit",(5,6)}
54+
'''

File_1.csv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Name, Age, Sport
2+
John Aalberg,31,Cross Country Skiing
3+
Minna Maarit Aalto,30,Sailing
4+
Win Valdemar Aaltonen,54,Art Competitions
5+
Wakako Abe,18,Cycling

File_1.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Line-1
2+
Line-2
3+
Line-3
4+
Line-4
5+
Line-6
6+
Line-5
7+
321
8+
3.14

File_read_write_1.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
'''
2+
author : Jaydatt
3+
file read write
4+
5+
Method-1 :
6+
file = open(fileName, "r" or "w")
7+
......
8+
file.close()
9+
10+
Method-2 (close file automatically):
11+
with open(fileName, "r" or "w") as f:
12+
......codes....
13+
.......
14+
15+
16+
Methods:
17+
18+
filevar.write(string) : Add a string to the end of the file. filevar must refer to a file that has been opened for writing.
19+
20+
filevar.writelines(List or Set or Array) : Add a string to the end of the file. filevar must refer to a file that has been opened for writing.
21+
22+
filevar.read() or filevar.read(n) : Read and return a string of n characters, or the entire file as a single string if n is not provided.
23+
24+
filevar.readline() or filevar.readline(n) : Read and return the next line of the file with all text up to and including the newline character
25+
26+
filevar.readlines() or filevar.readlines(n) :
27+
Returns a list of strings
28+
29+
filevar.tell() : get current position in file
30+
31+
filevar.seek(int offset ,int reference) or
32+
filevar.seek(int offset) reference By default 0 :
33+
offset : +value for right and -value for left
34+
reference:(0,1,2) By default 0.
35+
0: point at the beginning of the file
36+
1: point at the current file position
37+
2: point at the end of the file
38+
39+
40+
'''
41+
# program to write into file
42+
file = open("File_1.txt", 'w')
43+
str1 = "Line-1\n"
44+
str2 = "Line-2\n"
45+
list = ["Line-3\n","Line-4\n"]
46+
set = {"Line-5\n","Line-6\n"}
47+
val = 321
48+
flt = 3.14
49+
file.write(str1 + str2 )
50+
file.writelines(list)
51+
file.writelines(set)
52+
file.write(str(val) + "\n" + str(flt))
53+
file.flush()
54+
file.close()
55+
56+
57+
# program to read from file
58+
file = open("File_1.txt", 'r')
59+
60+
begining = file.tell() ## get current position in file
61+
print("begining: " , begining)
62+
63+
# seek(int offset ,int reference)
64+
# offset : +value for right and -value for left
65+
# reference:(0,1,2) By default 0.
66+
# 0: sets the reference point at the beginning of the file
67+
# 1: sets the reference point at the current file position
68+
# 2: sets the reference point at the end of the file
69+
file.seek(begining) # reference by default 0.
70+
71+
print("Total Characters : " , len(file.read()))
72+
73+
file.seek(begining)
74+
print("Total Lines : " , len(file.readlines()))
75+
76+
77+
78+
file.seek(begining)
79+
## read all line as String
80+
print("------------")
81+
read = file.read()
82+
print("type(read) : " , type(read))
83+
print("read : \n",read)
84+
85+
86+
file.seek(begining)
87+
## read only one line as String
88+
print("------------")
89+
readline = file.readline()
90+
print("type(readline) : " , type(readline))
91+
print(readline)
92+
readline = file.readline()
93+
print(readline)
94+
95+
96+
file.seek(begining)
97+
## read all lines as List
98+
print("------------")
99+
readlines = file.readlines()
100+
print("type(readlines) : " , type(readlines))
101+
print("readlines : ", readlines)
102+
103+
## Read lines of file directly with for loop
104+
file.seek(begining)
105+
print("------------")
106+
for line in file:
107+
print(line)
108+
109+
file.close()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy