Skip to content

Commit 18e842e

Browse files
authored
Initial Commit
1 parent 9eea9a4 commit 18e842e

File tree

90 files changed

+1979
-0
lines changed

Some content is hidden

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

90 files changed

+1979
-0
lines changed

I Basics/1 First Python Program.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
print('Aswin Barath')
2+
name = input('What is your name? Your Answer:')
3+
print(name)
4+
print('Helllloooo ' + name)

I Basics/10 Strings.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Strings
2+
print(type("Hi hello there"))
3+
print(type('Hey'))
4+
username = 'supercoder'
5+
password = 'supersecret'
6+
long_string = '''
7+
M
8+
WOW
9+
|O O|
10+
| | |
11+
|___|
12+
\_/
13+
'''
14+
print(long_string)
15+
first_name = 'Aswin '
16+
last_name = 'Barath'
17+
full_name = first_name + last_name
18+
print(full_name)
19+
20+
# String Concatenation
21+
print('Hello' + ' Aswin')
22+
23+
# Type conversion
24+
print(type(int(str(100))))
25+
a = str(100)
26+
b = int(a)
27+
c = type(b)
28+
print(c)
29+
30+
# Escape Sequence
31+
# Issue: weather = "It's "kind of" sunny"
32+
weather = "\t It\'s \"kind of\" sunny \n Hope you have a good day"
33+
print(weather)
34+
35+
# Formatted Strings
36+
37+
name = 'John Doe'
38+
age = 55
39+
print('hi ' + name + '. You are ' + str(age) + ' years old')
40+
41+
# Python 3 Update:-
42+
print(f'hi {name}. You are {age} years old')
43+
44+
# Python 2
45+
print('hi {}. You are {} years old'.format(name, age))
46+
print('hi {1}. You are {0} years old'.format(name, age))
47+
print('hi {new_name}. You are {new_age} years old'.format(new_name='Sally', new_age='19'))
48+
49+
# String Indexes
50+
selfish = '01234567'
51+
# Index - 01234567
52+
print(selfish[6])
53+
54+
# String Slicing - [start:stop:stepover]
55+
print(selfish[0:2])
56+
print(selfish[0:8])
57+
print(selfish[0:8:2])
58+
print(selfish[1:])
59+
print(selfish[:5])
60+
print(selfish[::1])
61+
print(selfish[-1])
62+
print(selfish[::-1])
63+
print(selfish[::-2])
64+
65+
# Immutability
66+
# We cannot reassign a string
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Built in Functions :-
2+
# str()
3+
# int()
4+
# float()
5+
# type()
6+
# print()
7+
greet = 'heeelllllooooo'
8+
print(greet[0:len(greet)])
9+
10+
# Methods :-
11+
# .format()
12+
# .lower()
13+
quote = 'to be or not to be'
14+
15+
print(quote.upper())
16+
print(quote.capitalize())
17+
print(quote.find('be'))
18+
print(quote.replace('be', 'me'))
19+
20+
print(quote)
21+
22+
quote2 = quote.replace('be', 'me')
23+
print(quote2)

I Basics/12 Booleans.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# booleans :-
2+
# bool
3+
name = 'Aswin'
4+
is_cool = False
5+
6+
is_cool = True
7+
8+
print(bool(1))
9+
print(bool(0))
10+
print(bool('True'))
11+
print(bool('False'))

I Basics/13 Type Conversion.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Facebook :-
2+
name = 'Aswin'
3+
age = 19
4+
relationship_status = 'single'
5+
6+
relationship_status = 'it\'s complicated'
7+
8+
print(relationship_status)
9+
10+
# Program that guesses your age
11+
birth_year = input('what year were you born:')
12+
age = 2020 - int(birth_year)
13+
print(f'Your age is:{age}')
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# To comment selected lines - command: ctrl + /
2+
3+
user_name = input('Enter your username:')
4+
password = input('Enter your password:')
5+
password_length = len(password)
6+
secret = '*' * password_length
7+
8+
print(f'Your password {secret} is {password_length} letters long')

I Basics/15 Lists.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Lists are like arrays
2+
li = [1, 2, 3, 4, 5]
3+
li2 = ['a', 'b', 'c']
4+
li3 = [1, 2, 'a', True]
5+
amazon_cart = ['notebooks', 'sunglasses']
6+
print(amazon_cart[0])
7+
print(amazon_cart[1])
8+
9+
# List Slicing
10+
amazon_cart = [
11+
'notebooks',
12+
'sunglasses',
13+
'toys',
14+
'grapes'
15+
]
16+
print(amazon_cart[0:2])
17+
print(amazon_cart[0::2])
18+
# We Know Strings are Immutable
19+
# Lists are Mutable
20+
amazon_cart[0] = 'laptop'
21+
print(amazon_cart[0:3])
22+
print(amazon_cart)
23+
new_cart = amazon_cart[0:3]
24+
new_cart[0] = 'gum'
25+
print(new_cart)
26+
27+
# new_cart simply points the same location
28+
new_cart = amazon_cart
29+
new_cart[0] = 'gum'
30+
print(amazon_cart)

I Basics/16 Matrix.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Matrix
2+
matrix = [
3+
[1, 2, 3],
4+
[2, 4, 6],
5+
[7, 8, 9]
6+
]
7+
8+
# Image of X stored as matrix :-
9+
matrix2 = [
10+
[1, 0, 1],
11+
[0, 1, 0],
12+
[1, 0, 1]
13+
]
14+
15+
print(matrix[0])
16+
print(matrix2[0])
17+
print(matrix[0][1])
18+
print(matrix2[0][1])

I Basics/17 List Methods.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Built in function
2+
basket = [1, 2, 3, 4, 5]
3+
print(len(basket))
4+
5+
# List Methods
6+
# adding
7+
basket.append(100)
8+
new_list = basket
9+
print('append method')
10+
print(basket)
11+
print(new_list)
12+
13+
basket.insert(4, 100)
14+
print('Insert method')
15+
print(basket)
16+
17+
basket.extend([101])
18+
print('Extend method')
19+
print(basket)
20+
21+
# removing
22+
basket.pop()
23+
basket.pop(4)
24+
popped = basket.pop(5)
25+
print('Pop methods')
26+
print(basket)
27+
print(popped)
28+
29+
basket.remove(2)
30+
print('Remove method')
31+
print(basket)
32+
33+
basket.clear()
34+
print('Clear method')
35+
print(basket)
36+
37+
trolley = ['c', 'a', 'b', 'c', 'd', 'e', 'c']
38+
# Index -> 0 1 2 3 4
39+
print('Index method')
40+
print(trolley.index('d', 0, len(trolley)))
41+
print('d' in trolley)
42+
print('x' in trolley)
43+
print('w' in 'I\'m Aswin')
44+
45+
print(trolley.count('c'))
46+
47+
# Exercise
48+
# using this list,
49+
basket2 = ["Banana", "Apples", "Oranges", "Blueberries"]
50+
51+
print(basket2)
52+
# 1. Remove the Banana from the list
53+
basket2.remove("Banana")
54+
print(basket2)
55+
# 2. Remove "Blueberries" from the list.
56+
basket2.pop()
57+
print(basket2)
58+
# 3. Put "Kiwi" at the end of the list.
59+
basket2.append('Kiwi')
60+
print(basket2)
61+
# 4. Add "Apples" at the beginning of the list
62+
basket2.insert(0, 'Apples')
63+
print(basket2)
64+
# 5. Count how many apples in the basket
65+
basket2.count('Apples')
66+
print(basket2)
67+
# 6. empty the basket
68+
basket2.clear()
69+
print(basket2)
70+
71+
basket3 = ['e', 'd', 'c', 'x', 'd', 'b', 'a']
72+
basket3.sort()
73+
print('Sort method')
74+
print(basket3)
75+
# Built in function
76+
print(sorted(basket3))
77+
print(basket3)
78+
new_basket = basket.copy()
79+
new_basket.sort()
80+
print(new_basket)
81+
print(basket3)
82+
83+
print(basket3)
84+
print('Reverse method')
85+
basket3.reverse()
86+
print(basket3)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Tricks in Lists
2+
basket = ['a', 'x', 'b', 'c', 'd', 'e', 'd']
3+
basket.sort()
4+
basket.reverse()
5+
print('Length of String')
6+
print(len(basket))
7+
print('Copy of Reverse using List Slicing')
8+
print(basket[::-1])
9+
print(basket)
10+
11+
print('List using range')
12+
print(list(range(101)))
13+
14+
# String method
15+
new_sentence = ' '.join(['hi', 'my', 'name', 'is', 'jojo'])
16+
print(new_sentence)
17+
18+
# Exercise
19+
# fix this code so that it prints a sorted list of all of our friends (alphabetical). Scroll to see answer
20+
friends = ['Simon', 'Patty', 'Joy', 'Carrie', 'Amira', 'Chu', 'Stanley']
21+
22+
friends.sort()
23+
print(friends)
24+
25+
# Solution: (keep in mind there are multiple ways to do this, so your answer may vary.
26+
# As long as it works that's all that matters!)
27+
# friends.extend(new_friend)
28+
# print(sorted(friends))

0 commit comments

Comments
 (0)