<jupyter_start><jupyter_text>Python Crash CourseThis notebook will just go through the basic topics in order:* Data types    * Numbers    * Strings    * Printing    * Lists    * Dictionaries    * Booleans    * Tuples     * Sets* Comparison Operators* if, elif, else Statements* for Loops* while Loops* range()* list comprehension* functions* lambda expressions* map and filter* methods  Data types Numbers<jupyter_code>1 + 1
1 * 3
1 / 2
2 ** 4
4 % 2
5 % 2
(2 + 3) * (5 + 5)<jupyter_output><empty_output><jupyter_text>Variable Assignment<jupyter_code># Can not start with number or special characters
name_of_var = 2
x = 2
y = 3
z = x + y
z<jupyter_output><empty_output><jupyter_text>Strings<jupyter_code>'single quotes'
"double quotes"
" wrap lot's of other quotes"<jupyter_output><empty_output><jupyter_text>Printing<jupyter_code>x = 'hello'
x
print(x)
num = 7
name = 'Ajay'
print('My number is: {one}, and my name is: {two}'.format(one=num,two=name))
print('My number is: {}, and my name is: {}'.format(num,name))
S='abcdefghijklmno'
S[2]
S[3:] #take from certain index 
S[:3] #take to certain index<jupyter_output><empty_output><jupyter_text>Lists<jupyter_code>[1,2,3]
['hi',1,[1,2]]
my_list = ['a','b','c']
my_list.append('d')
my_list
my_list[0]
my_list[1]
my_list[1:]
my_list[:1]
my_list[0] = 'NEW'
my_list
nest = [1,2,3,[4,5,['target','here']]]
nest[3]
nest[3][2]
nest[3][2][0]<jupyter_output><empty_output><jupyter_text>Dictionaries<jupyter_code>d = {'key1':'item1','key2':'item2'}
d
d['key1']
dic={'k1':[1,2,3],'k2':[1,[2,3],4,[5,6]]}
dic['k2']
dic['k2'][3]
d={'k1':{'ik':[1,2,[2,3],5]}}
d['k1']['ik'][2]<jupyter_output><empty_output><jupyter_text>Booleans<jupyter_code>True
False<jupyter_output><empty_output><jupyter_text>Tuples<jupyter_code>t = (1,2,3)#uses () #immutable 
t[0]
t[0] = 'NEW'<jupyter_output><empty_output><jupyter_text>Sets<jupyter_code>set={1,2,3}
set
s={1,2,3,1,2,1,2,3,3,3,3,2,2,2,1,1,2} #can only have unique element 
s.add(4);s.add(5);
s<jupyter_output><empty_output><jupyter_text>Comparison Operators<jupyter_code>1 > 2
1 < 2
1 >= 1
1 <= 4
1 == 1
1!=5
'hi' == 'bye'<jupyter_output><empty_output><jupyter_text>Logic Operators<jupyter_code>(1 > 2) and (2 < 3)
(1 > 2) or (2 < 3)
(1 == 2) or (2 == 3) or (4 == 4)<jupyter_output><empty_output><jupyter_text>if,elif, else Statements<jupyter_code>if 1 < 2:
    print('Yep!')
if 1 < 2:
    print('yep!')
if 1 < 2:
    print('first')
else:
    print('last')
if 1 > 2:
    print('first')
else:
    print('last')
if 1 == 2:
    print('first')
elif 3 == 3:
    print('middle')
else:
    print('Last')<jupyter_output>middle<jupyter_text>for Loops<jupyter_code>seq = [1,2,3,4,5]
for item in seq:
    print(item)
for item in seq:
    print('Yep')
for jelly in seq:
    print(jelly+jelly)<jupyter_output>2
4
6
8
10<jupyter_text>while Loops<jupyter_code>i = 1
while i < 5:
    print('i is: {}'.format(i))
    i = i+1<jupyter_output>i is: 1
i is: 2
i is: 3
i is: 4<jupyter_text>range()<jupyter_code>range(5)
for i in range(5):
    print(i)
list(range(5))<jupyter_output><empty_output><jupyter_text>list comprehension<jupyter_code>x = [1,2,3,4]
out = []
for item in x:
    out.append(item**3)
print(out)
x
lc=[item**2 for item in x]
lc<jupyter_output><empty_output><jupyter_text>functions<jupyter_code>def my_func(param1='Ajay'):
    """
    Docstring goes here.
    """
    print('Hello ' +param1)
my_func
my_func()
my_func('Chandran')
my_func(param1='new Guy')
def square(x):
    """this function square number"""
    return x**2
out = square(2) #press Shift tab to get more information of the function 
print(out)<jupyter_output>4<jupyter_text>lambda expressions<jupyter_code>def times2(var):
    return var*2
times2(12)
def times2(var):return var*2 # getting rid of 'def','return' and name of the funtion 'times2'
times2(3)
lambda var: var*2
lam=lambda var: var*2
lam(4)<jupyter_output><empty_output><jupyter_text>map and filter<jupyter_code>seq = [1,2,3,4,5]
map(times2,seq)#map-> loop to seq list to a function 
list(map(times2,seq))
t=list(map(times2,seq))
list(map(lambda var: var*2,seq))
filter(lambda item: item%2 == 0,seq)#Filtering out which match the condition
list(filter(lambda item: item%2 == 0,seq))<jupyter_output><empty_output><jupyter_text>methods<jupyter_code>st = 'hello my name is Ajay'
st.lower()
st.upper()
st.split()# split into list
tweet = 'Go Sports! #Sports'
tweet.split('#')
tweet.split('#')[1]
d={'key1':'item1','key2':'item2'}
d.keys()
d.items()
lst = [1,2,3]
lst.pop()# act like stack and remove last
lst
'x' in [1,2,3] #search a valuei in
'x' in ['x','y','z']<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18177855274629467, 'fraction_numerical': 0.04511769834350479, 'mean_word_length': 6.29570747217806, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '20', 'dir': 'jupyter-structured-clean-dedup', 'id': '299234', 'license': 'MIT', 'n_tokens_mistral': 2061, 'n_tokens_neox': 1979, 'n_words': 417, 'path': 'Day 1.ipynb', 'repo_name': 'Ajay-Chandran/DataScienceWithPython', 'size': '4588'}