Skip to content
This repository was archived by the owner on Dec 27, 2022. It is now read-only.

Commit 3caa265

Browse files
committed
first commit
0 parents  commit 3caa265

File tree

11 files changed

+397
-0
lines changed

11 files changed

+397
-0
lines changed

.vscode/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"python.testing.unittestArgs": [
3+
"-v",
4+
"-s",
5+
".",
6+
"-p",
7+
"*test.py"
8+
],
9+
"python.testing.pytestEnabled": false,
10+
"python.testing.unittestEnabled": true
11+
}

1. Variables.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Variables
2+
# Assign1
3+
x = "Orange"; y = z = "Banana"
4+
print(x)
5+
print(y)
6+
print(z)
7+
#Orange
8+
#Banana
9+
#Banana
10+
11+
# Assign2
12+
x = 5; y = "John"
13+
print(type(x))
14+
#<class 'int'>
15+
print(y, "is", x)
16+
#John is 5
17+
18+
# Assign3
19+
def myfunc():
20+
print("Name is " + y)
21+
myfunc()
22+
#Name is John

2. Numbers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Numbers
2+
# Random
3+
import random
4+
print(random.randrange(1, 10))
5+
#1 to 10
6+
x = int(2.8) # y will be 2
7+
y = float(2.8) # y will be 2.8
8+
z = float("3") # z will be 3.0
9+
print ("x:", x, " y:", y, " z:", z)
10+
#x: 2 y: 2.8 z: 3.0

3. String.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# String
2+
# Multiline
3+
x = """Lorem ipsum dolor sit amet,
4+
consectetur adipiscing elit,
5+
sed do eiusmod tempor incididunt
6+
ut labore et dolore magna aliqua."""
7+
print(x)
8+
9+
# Basic Print
10+
x = "Hello, Python!"
11+
print(x[1])
12+
#e
13+
print(x[2:5])
14+
#llo
15+
16+
# Each word on new Line
17+
for x in "banana":
18+
print(x)
19+
#b
20+
#a
21+
#n
22+
#a
23+
#n
24+
#a
25+
26+
# Advanced output
27+
x = "Hello, World!"
28+
print(len(x))
29+
#13
30+
print(x.upper())
31+
#HELLO, WORLD!
32+
y = x + x
33+
print(y)
34+
#Hello, World!Hello, World!
35+
36+
txt = "The best things in life are free!"
37+
print("free" in txt)
38+
#True
39+
if "expensive" not in txt:
40+
print("No, 'expensive' is NOT present.")
41+
#No, 'expensive' is NOT present.
42+
43+
# Multi variable
44+
quantity = 3
45+
itemno = 567
46+
price = 49.95
47+
myorder = "I want {} pieces of item {} for {} dollars."
48+
print(myorder.format(quantity, itemno, price))
49+
#I want 3 pieces of item 567 for 49.95 dollars.
50+
51+
x = """\'1 \\2 \n3 \t4"""
52+
print(x)
53+
#'1 \2
54+
#3 4

4. List-Touple-Set.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# List, Tuple & Set
2+
thislist = ["apple", "banana"]
3+
4+
#basic print
5+
print(thislist[-1])
6+
#banana
7+
print(thislist[0:2])
8+
#['apple', 'banana']
9+
print(thislist[0:])
10+
#['apple', 'banana']
11+
12+
#add
13+
thislist.insert(9, "watermelon")
14+
print(thislist)
15+
#['apple', 'banana', 'watermelon']
16+
thislist.append("cherry")
17+
print(thislist)
18+
#['apple', 'banana', 'watermelon', 'cherry']
19+
20+
#extend
21+
tropical = ["pineapple", "papaya"]
22+
thislist.extend(tropical)
23+
print(thislist)
24+
#['apple', 'banana', 'watermelon', 'cherry', 'pineapple', 'papaya']
25+
26+
#remove
27+
thislist.remove("banana")
28+
print(thislist)
29+
#['apple', 'watermelon', 'cherry', 'pineapple', 'papaya']
30+
thislist.clear()
31+
print(thislist)
32+
#[]
33+
34+
#more
35+
thislist = ["apple", "banana", "cherry"]
36+
for x in thislist:
37+
print(x)
38+
#apple
39+
#banana
40+
#cherry
41+
i = 0
42+
while i < len(thislist):
43+
print(thislist[i])
44+
i = i + 1
45+
#apple
46+
#banana
47+
#cherry
48+
49+
#sort
50+
thislist = [100, 50, 65, 82, 23]
51+
thislist.sort(reverse = True)
52+
print(thislist)
53+
#[100, 82, 65, 50, 23]
54+
55+
#copy list
56+
thislist = ["apple", "banana", "cherry"]
57+
mylist = thislist.copy()
58+
print(mylist)
59+
60+
#join list
61+
list1 = ["a", "b", "c"]
62+
list2 = [1, 2, 3]
63+
list3 = list1 + list2
64+
print(list3)
65+
#['a', 'b', 'c', 1, 2, 3]
66+
67+
68+
# Tuples(Cant be changed)
69+
thistuple = ("apple", "banana", "cherry")
70+
print(thistuple)
71+
#('apple', 'banana', 'cherry')
72+
print(len(thistuple))
73+
#3
74+
print(thistuple[1])
75+
#banana
76+
77+
#remove
78+
thistuple = ("apple", "banana", "cherry")
79+
y = list(thistuple)
80+
y.remove("apple")
81+
thistuple = tuple(y)
82+
print(thistuple)
83+
84+
#multiply tuple
85+
fruits = ("apple")
86+
mytuple = fruits * 2
87+
print(mytuple)
88+
#appleapple
89+
90+
#intersection
91+
x = {"apple", "banana", "cherry"}
92+
y = {"google", "microsoft", "apple"}
93+
x.intersection_update(y)
94+
print(x)
95+
#{'apple'}

5. Dictionary.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Dictionary
2+
thisdict = {
3+
"brand": "Ford",
4+
"model": "Mustang",
5+
"year": 1964,
6+
"year": 2020
7+
}
8+
#forced change
9+
thisdict["year"] = 2018
10+
11+
#update
12+
thisdict.update({"color": "red"})
13+
14+
#pop-delete
15+
thisdict.pop("model")
16+
17+
print(thisdict)
18+
#{'brand': 'Ford', 'year': 2018, 'color': 'red'}
19+
20+
print(thisdict["brand"])
21+
#Ford
22+
23+
print(len(thisdict))
24+
#3

6. Loops.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#LOOP
2+
#IF-Else
3+
a = 200
4+
b = 33
5+
if b > a:
6+
print("b is greater than a")
7+
elif a == b:
8+
print("a and b are equal")
9+
else:
10+
print("a is greater than b")
11+
#a is greater than b
12+
13+
14+
#While
15+
i = 4
16+
while i < 6:
17+
print(i)
18+
i += 1
19+
#4
20+
#5
21+
22+
#continue
23+
fruits = ["apple", "banana", "cherry"]
24+
for x in fruits:
25+
if x == "banana":
26+
continue
27+
print(x)
28+
#apple
29+
#cherry
30+
31+
#range
32+
for x in range(2):
33+
print(x)
34+
#0
35+
#1
36+
37+
#nested Loop
38+
x = ["1", "2", "3"]
39+
y = ["4", "5", "6"]
40+
for a in x:
41+
for b in y:
42+
print(a,b)

7. Functions.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#Functions
2+
def my_function(fname, lname):
3+
print(fname + "-" + lname)
4+
5+
my_function("Emil", "Refsnes")
6+
#Emil-Refsnes
7+
8+
def my_function(c1,c2,c3):
9+
print("Lowest number is-" + c1)
10+
print("followed by-" + c2 + c3)
11+
my_function(c1="2", c2="3", c3="5")
12+
#Lowest number is-2
13+
#followed by-35
14+
15+
#lambda
16+
x = lambda a : a + 10
17+
print(x(5))
18+
#15
19+
20+
def myfunc(n):
21+
return lambda a : a * n
22+
mydoubler = myfunc(2)
23+
print(mydoubler(11))
24+
#22

8.Classes & Objects.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#Classes & Objects
2+
class Person:
3+
def __init__(self, name, age):
4+
self.name = name
5+
self.age = age
6+
7+
p1 = Person("John", 36)
8+
#modify object
9+
p1.age = 40
10+
print(p1.age)
11+
#40
12+
13+
#delete object
14+
del p1.name
15+
#error!

9. Inheritance.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#Inheritance
2+
class Person:
3+
def __init__(self, fname, lname):
4+
self.firstname = fname
5+
self.lastname = lname
6+
7+
def printname(self):
8+
print(self.firstname, self.lastname)
9+
10+
#Use the Person class to create an object, and then execute the printname method:
11+
12+
x = Person("John", "Doe")
13+
x.printname()

0 commit comments

Comments
 (0)