Skip to content

Commit 2d0da3c

Browse files
committed
Initial Commit
1 parent 4778cd7 commit 2d0da3c

39 files changed

+1579
-2
lines changed

ABC.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This is a text file.
2+
This happens to be the place which i am going to use for the file operation in python.
3+

ABCD.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
one
2+
two
3+
three

Afunc.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def Multiplication(a, b, c):
2+
print("a= ", a, "b= ", b, "c= ", c)
3+
print("Product is ", a*b*c)
4+
5+
if __name__=="__main__":
6+
Multiplication(2,3,4)
7+
8+
print("This is:- ",__name__)
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Input
2+
a= input("Enter the value:- ")# Don't forget to give input each time this code is executed
3+
b= int(input("Only Integer else there will be an error:- "))
4+
c= float(input("Only Float else there will be an error:- "))
5+
6+
# Output
7+
print(a)
8+
print(b+ c)
9+
print(5+2)
10+
print("Python")
11+
print(7,8.12,"Python ", sep= "-", end= "$")
12+
13+
# Multiple Output
14+
print(a,7,8,6+5)
15+
16+
# Comments - lines that will not be executed
17+
18+
# Single- Line Comment
19+
20+
'''
21+
Multi- Line Comments used to comment multiple line,
22+
instead of using # each time.
23+
'''
24+
"""
25+
We can also use Double- Quoted-
26+
Three- inverted- commas
27+
"""
28+
29+
# Escape Sequence Character- For functions that normally cannot be used in strings
30+
31+
print("This is for escape sequence\t \" We can use\" symbol too\n Escape Sequence")
+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Variables are like Containers that hold data
2+
# Variables can be updated i.e. they are dynamic not static
3+
4+
a1=1
5+
B1=2
6+
_c1=3
7+
# not 1c_=4
8+
print( a1, B1, _c1)
9+
print( "This is type of a1", type( a1))
10+
11+
# Data type specifies the type of value a variable holds.
12+
13+
'''
14+
5 types of data types
15+
1. Numeric:- int, float, complex
16+
2. String
17+
3. Boolean:- True, False
18+
4. Sequenced:- list- [], tuple- ()-> list is mutable( can be modified) and tuple is immutable( cannot be modified)
19+
5. Mapped:- dictionary
20+
'''
21+
print("Numeric Data Type= ",3," ",7.83," ",6+2j)
22+
print("String Data Type= ","This is Python String",'And we are learning Programming')
23+
print("Boolean Data Type= ",True)
24+
print("Sequenced Data Type= ",[12,15,16,18]," ",(11,14,17,19))
25+
print("Dictionary= ", {"name": "Rohan", "age": 25, "Student": True, "Stream": "MBA"})
26+
27+
# Explicit typecasting- Done by user
28+
string = "15"
29+
number = 7
30+
string_number = int(string) # throws an error if the string is not a valid integer
31+
sum= number + string_number
32+
print("The Sum of both the numbers is: ", sum)
33+
34+
# Implicit type casting- Done by Python automatically
35+
36+
# Python converts a to int
37+
a = 7
38+
print(type(a))
39+
40+
# Python converts b to float
41+
b = 3.0
42+
print(type(b))
43+
44+
# Python converts c to float
45+
c = a + b
46+
print(c)
47+
print(type(c))
48+
49+
# Global and Local Variables
50+
# Variables that are defined inside a function body have a local scope, and those defined outside have a global scope
51+
52+
a = 1
53+
def x1():
54+
print('Inside x1() : ', a)
55+
def x2():
56+
a = 2
57+
print('Inside x2() : ', a)# Here a= 2 using local a
58+
def x3():
59+
global a
60+
a = 3
61+
print('Inside x3() : ', a) # Here a= 3 using global a 'cos we have written global a first
62+
print('global : ', a)
63+
x1()
64+
print('global : ', a)
65+
x2()
66+
print('global : ', a)
67+
x3()
68+
print('global : ', a) # value of a has changed in function x3
69+

Basics/03. Operators.py

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Operators:- signs or keywords used to perform specific operation on multiple values or variables.
2+
# Types of Operators:-
3+
# Arithmetic Operators- +, -, *, /, **, //, %
4+
# Comparison Operators- <, >, <=. >=, ==, !=
5+
# Assignment Operators- =, +=, -=, *=, %=
6+
# Logical Operators- AND, OR, NOT
7+
# Bitwise Operators- &, |, <<, >>, -, ^
8+
9+
# Arithmetic Operators
10+
a=3
11+
b=4
12+
c=6
13+
print(a+b, " ", a-b, " ", a*b, " ", c/b, " ", b**a, " ", c//b, " ", c%b)
14+
15+
x= "Lord "
16+
y= "Voldemort "
17+
18+
# Concatenation of Strings
19+
z= x+y
20+
print(z)
21+
22+
# Replication of String
23+
print(z*a)
24+
25+
# Comparison Operators
26+
27+
print(a>b, " ", a<b, " ", a==b, " ", a!=b, " ", a>=b, " ", a<=b)
28+
29+
# 'is' vs '=='
30+
31+
a, b= 3, 3 # Constant Immutable
32+
x, y = [1, 2, 3], [1, 2, 3]
33+
print( a==b, " ", a is b)
34+
print( x==y, " ", x is y)
35+
36+
# Assignment Operators
37+
38+
d= 16
39+
print(d)
40+
a+= 3
41+
print( a)
42+
b-= 2
43+
print( b)
44+
c*= 2
45+
print( c)
46+
c%= 5
47+
print( c)
48+
a/=2
49+
print( a)
50+
51+
# Logical Operators
52+
53+
if( a>1 and b==2):
54+
print(" And is working")
55+
56+
if( a>1 or b<2):
57+
print(" If is working")
58+
59+
if (not( a<1 and b>2)):
60+
print(" Not is working")
61+
62+
# Bitwise Operators
63+
64+
x = 5 # Binary: 0101
65+
y = 3 # Binary: 0011
66+
result = x & y # Binary: 0001
67+
print(result)
68+
x = 5 # Binary: 0101
69+
y = 3 # Binary: 0011
70+
result = x | y # Binary: 0111
71+
print(result)
72+
x = 5 # Binary: 0101
73+
y = 3 # Binary: 0011
74+
result = x ^ y # Binary: 0110
75+
print(result)
76+
x = 5 # Binary: 0101
77+
result = ~x # 2's complement
78+
print(result)
79+
x = 5 # Binary: 0101
80+
result = x << 2
81+
print(result)
82+
x = 5 # Binary: 0101
83+
result = x >> 2 # Binary: 0001
84+
print(result)

Basics/04. Strings.py

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Anything that is between single or double quotation marks is string.
2+
# It is basically a collection of Characters. Strings are Immutable.
3+
4+
name = "Batman" # Batman is string
5+
print("Hello "+name) # Hellow is string
6+
b= "mohan's life is pretty lavish!!!"
7+
d="PETROL136"
8+
e=" Ranger "
9+
print(b)
10+
11+
# Multi-line String
12+
13+
a= """
14+
An Apple a day keeps the doctor away
15+
But what if i am the doctor and
16+
i eat an Apple everyday,
17+
Will i be seperated from myself?
18+
Sounds interesting!
19+
"""
20+
print(a)
21+
22+
# length of String
23+
24+
x= len(a)
25+
print('length of a is:- ',x)
26+
27+
# Accessing Specific Characters of String
28+
29+
print(name[3])
30+
31+
# Slicing
32+
print(a[22:25])
33+
print(a[:5])
34+
print(a[-8:])
35+
print(a[-14:148])
36+
print(a.upper())
37+
print(a.lower())
38+
print(a.replace("Apple", "doctor"))
39+
print(a.split(" "))
40+
print(a.count("Apple"))
41+
print(a.find("i"))
42+
print(a.index("i")) # Raises error when the value is not found
43+
print(a.swapcase())
44+
print(a.isprintable())
45+
print(a.isspace())
46+
print(a.istitle())
47+
print(a.title())
48+
49+
print(b.rstrip("!"))
50+
print(b.capitalize())
51+
print(b.center(50,"."))
52+
print(b.endswith("."))
53+
print(b.islower())
54+
print(b.istitle())
55+
print(b.title())
56+
print(b.startswith("mohan's"))
57+
58+
print(d.isalnum())
59+
print(d.isupper())
60+
61+
print(e.strip())
62+
63+
print(name.swapcase())
64+
print(name.isalpha())
65+
66+
# String Formatting or f-string
67+
b= "Shyam"
68+
c= "Wait for some time"
69+
a= "Welcome {} to this place we would like you to {}, right {}."
70+
x= "Welcome {0} to this place we would like you to {1}, right {1}."
71+
y= f"Welcome {b} to this place we would like you to {c}, right {c}."
72+
print(a.format(b,c,b))
73+
print(x.format(b,c,b))
74+
print(y)
75+
Weight=68.888
76+
print(f"Weight is {Weight:.1f}")
77+
print(f"The format of {{a}} will be give in the right way {2*4}")

Basics/05. If- elif- else.py

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'''
2+
An if-else loop is a conditional statement in programming that allows you to execute different code blocks based on
3+
whether a specified condition is true or false. It's a fundamental control flow structure that enables your program to
4+
make decisions and perform actions accordingly.
5+
'''
6+
7+
# If Loop
8+
9+
a= input("Enter name:- ")
10+
b= "power"
11+
if(type(a)== type(b)):
12+
print("String ")
13+
14+
# If- else Loop
15+
16+
a= int(input("Enter your age:- "))
17+
if(a>18):
18+
print("You can Vote")
19+
else:
20+
print("You cannot Vote")
21+
22+
# If- elif Loop
23+
24+
Selling_Price = int(input("Enter Selling Price of Your Product:- "))
25+
Cost_Price = int(input("Enter Cost Price of Your Product:- "))
26+
if (Selling_Price< Cost_Price):
27+
print("Profit ")
28+
elif(Selling_Price== Cost_Price):
29+
print("Nothing Gained")
30+
else:
31+
print("Loss")
32+
33+
# Nested If Loop
34+
35+
number = int(input("Enter any number:- "))
36+
if (number < 0):
37+
print("Negative Number")
38+
elif (number > 0):
39+
print("Positive Number")
40+
if (number <= 10):
41+
print("Number in range 1-10")
42+
elif (number > 10 and number <= 20):
43+
print("Number in range 11-20")
44+
else:
45+
print("Number is greater than 20")
46+
else:
47+
print("Number is zero")
48+
49+
# Ternary If- Else
50+
x=10
51+
y=50
52+
print(x) if x<y else print(y)if x>y else print(0)

Basics/06. Match Case.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'''
2+
General Syntax for Match- Case
3+
match value:
4+
case pattern1:
5+
# Code to execute if value matches pattern1
6+
case pattern2:
7+
# Code to execute if value matches pattern2
8+
case _:
9+
# Code to execute if value doesn't match any previous patterns
10+
11+
'''
12+
x = int(input("Enter Number: "))
13+
# x is the variable to match
14+
match x:
15+
# if x is 0
16+
case 0:
17+
print("x is zero")
18+
# case with if-condition
19+
case 8 if x % 2 == 0:
20+
print("x % 2 == 0 and case is 8")
21+
# Empty case with if-condition
22+
case _ if x < 10:
23+
print("x is < 10")
24+
case _ if x!=90:
25+
print(x, "is not 90")
26+
case _ if x%3!=0:
27+
print(x, "is not 80")
28+
case _: # It is basically an else.
29+
print(x)

Basics/07. For loop.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name = 'Saurabh'
2+
for i in name:
3+
print(i, end=", ")
4+
5+
Directions= ["North ", "South", "East ", "West"]
6+
for i in Directions:
7+
print("Direction", i, end= ",")
8+
9+
for x in range(5):
10+
print(x)
11+
12+
for k in range(2,8):
13+
print(k)
14+
15+
for i in range(5):
16+
print("Cool")
17+
else:
18+
print("Warm")
19+
20+
# Enumerate
21+
22+
a=[10,22,3,45,56,27.11]
23+
for a,b in enumerate(a, start= -1):
24+
print(b)
25+
if(a==3):
26+
print("Enumerated Successfully")

0 commit comments

Comments
 (0)