├── Chapter01
├── back_slash.py
├── escape_sequence.py
├── formatted_output1.py
├── formatted_output2.py
├── hello_world_1.py
├── hello_world_2.py
├── single_double_comments.py
├── single_inside_quotes2.py
├── single_quote_inside_quotes1.py
├── string_concatenation.py
├── strings_inside_quotes.py
├── tripple_comments1.py
└── tripple_comments2.py
├── Chapter03
├── excercise1.py
└── excercise2.py
├── Chapter04
├── excercise
│ ├── indexecercise.py
│ ├── list-sortsum.py
│ └── listexcercise1.py
├── listcmp1.py
├── listsort.py
├── listsortcomp.py
└── listsquar.py
├── Chapter05
├── excecisedict1.py
├── forloopitems.py
├── forloopiter.py
├── forloopkey.py
├── has_key1.py
├── inkey.py
└── onelineexcercis1.py
├── Chapter06
├── break_block.py
├── continue_statement.py
├── for_block_1.py
├── if_block.py
├── if_elif_else_block.py
├── if_else_block.py
└── nested_loops.py
├── Chapter07
├── function_calling.py
├── function_with_argument_n_return_value.py
├── function_with_arguments.py
├── function_with_default_argument.py
├── function_with_key_value_pair_as_variable_length_argument.py
├── function_with_no_argument.py
├── function_with_variable_length.py
├── global_variable.py
├── pass_by_ref_vs_value1.py
├── pass_by_ref_vs_value2.py
├── variable_scope.py
├── variable_scope1.py
└── variable_scope2.py
├── Chapter08
├── alice1.py
├── mod1.py
├── mod2.py
├── mod3.py
├── mod4.py
├── mod5.py
├── module1.py
├── module1.pyc
├── module2.py
├── module2.pyc
├── myprog.py
├── myprog.pyc
├── sound_conversion
│ ├── __init__.pyc
│ ├── rectomp3.py
│ ├── rectomp3.pyc
│ ├── rectowav.py
│ ├── rectowma.py
│ └── rectowma.pyc
└── voice_changer.py
├── Chapter09
├── batman.txt
├── calc.py
├── divide1.py
├── divied.py
├── emp1.dat
├── emp2.dat
├── exceptiontype.py
├── filecpickle1.py
├── filepickle1.py
├── filepickle2.py
├── filepickle3.py
├── filepickle4.py
├── filewrite1.py
├── filewrite2.py
├── filewritea.py
├── filewritea1.py
├── filewriteline.py
├── finally1.py
├── findword.py
├── motivation.txt
├── newmotivation.txt
├── readcount1.py
├── readfile.py
├── readfileforloop.py
├── readline1.py
├── readlinecount.py
├── readlines1.py
├── sample1.txt
├── userdefined1.py
├── userdefined2.py
└── wwerockquotes.txt
├── Chapter10
├── Counter_input.txt
├── default_dict_example.py
├── default_dict_example3.py
├── default_dict_example4.py
├── default_dict_list_of_tuples.py
├── default_dict_with_lambda.py
├── deque_consumption.py
├── deque_example.py
├── deque_rotation.py
├── named_tuple.py
├── named_tuple_with_list_values.py
├── ordered_vs_normal_dict.py
├── populating_deque.py
├── reading_text_file.py
├── reading_text_file1.py
├── replacing_value_from_named_tuple.py
├── set_operations_of_Counter.py
├── sorting_ordered_dict.py
├── sorting_ordered_dict_based_on_values.py
└── usage_of_counter.py
├── Chapter11
├── class1.py
├── class2.py
├── classinheri1.py
├── classinheri2.py
├── classinit.py
├── classinstance1.py
├── classinstance2.py
├── classinstance3.py
├── classinstance4.py
├── classinstance5.py
├── classinstance6.py
├── classmethod1.py
├── classmethod2.py
├── classmethod3.py
├── classmultilevel.py
├── classmultiple.py
├── classoperator1.py
├── classoperator2.py
├── classoperator3.py
├── classoperator4.py
├── classoperator5.py
├── classover1.py
├── methodclass1.py
├── private1.py
└── staticmethod1.py
├── LICENSE
└── README.md
/Chapter01/back_slash.py:
--------------------------------------------------------------------------------
1 | print "Hello \
2 | world "
--------------------------------------------------------------------------------
/Chapter01/escape_sequence.py:
--------------------------------------------------------------------------------
1 | print 'a'
2 | print '\t\tHermit'
3 | print 'i know , they are \'great\' '
4 |
--------------------------------------------------------------------------------
/Chapter01/formatted_output1.py:
--------------------------------------------------------------------------------
1 | print "Name", "Marks", "Age"
2 | print "John Doe", 80.67, "27"
3 | print "Bhaskar", 76.908, "27"
4 | print "Mohit", 56.98, "25"
--------------------------------------------------------------------------------
/Chapter01/formatted_output2.py:
--------------------------------------------------------------------------------
1 | print "Name Marks Age"
2 | print ( "%s %14.2f %11d" % ("John Doe", 80.67, 27))
3 | print ( "%s %12.2f %11d" %("Bhaskar" ,76.901, 27))
4 | print ( "%s %3.2f %11d" %("Mohit", 56.98, 25))
--------------------------------------------------------------------------------
/Chapter01/hello_world_1.py:
--------------------------------------------------------------------------------
1 | print "Hello World!"
--------------------------------------------------------------------------------
/Chapter01/hello_world_2.py:
--------------------------------------------------------------------------------
1 | print "Hello World!"
2 | print "Hello World!"
--------------------------------------------------------------------------------
/Chapter01/single_double_comments.py:
--------------------------------------------------------------------------------
1 | #This is a single line comment in Python
2 |
3 | print "Hello World" #This is a single comment in Python
4 |
5 | """ For multi-line
6 | comment use three
7 | double quotes
8 | ...
9 | """
10 | print "Hello World!"
--------------------------------------------------------------------------------
/Chapter01/single_inside_quotes2.py:
--------------------------------------------------------------------------------
1 | print "Hey there it's a cow"
--------------------------------------------------------------------------------
/Chapter01/single_quote_inside_quotes1.py:
--------------------------------------------------------------------------------
1 | print 'Hey there it's a cow'
--------------------------------------------------------------------------------
/Chapter01/string_concatenation.py:
--------------------------------------------------------------------------------
1 | print "Only way to join" + "two strings"
--------------------------------------------------------------------------------
/Chapter01/strings_inside_quotes.py:
--------------------------------------------------------------------------------
1 | print "Hello World 'Mr' Bond"
2 | print 'old world "but" still good'
--------------------------------------------------------------------------------
/Chapter01/tripple_comments1.py:
--------------------------------------------------------------------------------
1 | print '''I am mad in love
2 | do you think
3 | I am doing
4 | the right thing '''
--------------------------------------------------------------------------------
/Chapter01/tripple_comments2.py:
--------------------------------------------------------------------------------
1 | print """I am mad in love
2 | do you think
3 | I am doing
4 | the right thing """
--------------------------------------------------------------------------------
/Chapter03/excercise1.py:
--------------------------------------------------------------------------------
1 | url = "http://www.thapar.edu/index.php/about-us/mission"
2 |
3 | url_list = url.split("/")
4 |
5 | domain_name = url_list[2]
6 | print domain_name.replace("www.","")
7 |
8 |
--------------------------------------------------------------------------------
/Chapter03/excercise2.py:
--------------------------------------------------------------------------------
1 | url_tup = ('www', 'thapar', 'edu','index', 'php','about-us','mission')
2 | url1 = ".".join(url_tup[:3])
3 |
4 | url2 = "/".join(url_tup[3:])
5 |
6 | print url1+"/"+url2
7 |
--------------------------------------------------------------------------------
/Chapter04/excercise/indexecercise.py:
--------------------------------------------------------------------------------
1 | list1 = [1,2,4,5,1,1,4,1,56]
2 | list2 = []
3 | for i in xrange(len(list1)):
4 | if list1[i]==1:
5 | list2.append(i)
6 | print list2
7 |
8 | print [i for i in xrange(len(list1)) if list1[i]==1 ]
--------------------------------------------------------------------------------
/Chapter04/excercise/list-sortsum.py:
--------------------------------------------------------------------------------
1 | list1 = [(1,5),(9,0),(12,3),(5,4),(13,6),(1,1)]
2 |
3 | def sum1(tup1):
4 | a,b = tup1
5 | c = a+b
6 | return c
7 |
8 | list1.sort(key=sum1)
9 | print list1
10 |
--------------------------------------------------------------------------------
/Chapter04/excercise/listexcercise1.py:
--------------------------------------------------------------------------------
1 | list1[1][2][1][4:]
--------------------------------------------------------------------------------
/Chapter04/listcmp1.py:
--------------------------------------------------------------------------------
1 | list1 = [10,9,3,7,2,1,23,1,561,1,1,96,1]
2 |
3 | def cmp1(x,y):
4 |
5 | if x == 1 or y==1:
6 | c = y-x
7 | else:
8 | c = x-y
9 | return c
10 |
11 | list1.sort(cmp = cmp1)
12 |
13 | print list1
--------------------------------------------------------------------------------
/Chapter04/listsort.py:
--------------------------------------------------------------------------------
1 | def fun1(x):
2 | return x[1]
3 |
4 | list_tup = [("a",4),("b",1),("v",5),("f",2)]
5 | list_tup.sort(key= fun1)
6 | print list_tup
--------------------------------------------------------------------------------
/Chapter04/listsortcomp.py:
--------------------------------------------------------------------------------
1 | def add1(x,y):
2 |
3 | if x>10 or y>10:
4 | c = 1
5 | else :
6 | c = x-y
7 | return c
8 |
9 | list_tup = [9,12,90,3,9,1,7,1,2,8,1,1,96,1]
10 | list_tup.sort(cmp=add1)
11 | print list_tup
--------------------------------------------------------------------------------
/Chapter04/listsquar.py:
--------------------------------------------------------------------------------
1 | list1 = [2,3,4,5,6]
2 | list2 = []
3 | for each in list1:
4 | if each%2== 0:
5 | list2.append(each*each)
6 | print list2
7 |
8 |
--------------------------------------------------------------------------------
/Chapter05/excecisedict1.py:
--------------------------------------------------------------------------------
1 | list1 = [1,2,3,4,5]
2 | list2 = ["a", "b", "c","d", "e"]
3 | dict1 = {}
4 | for index1 in xrange(len(list1)):
5 | dict1[list1[index1]] = list2[index1]
6 | print dict1
--------------------------------------------------------------------------------
/Chapter05/forloopitems.py:
--------------------------------------------------------------------------------
1 | port1 = {21: "FTP", 22 :"SSH", 23: "telnet", 80: "http"}
2 | for k,v in port1.items():
3 | print k," : ", v
4 |
--------------------------------------------------------------------------------
/Chapter05/forloopiter.py:
--------------------------------------------------------------------------------
1 | port1 = {21: "FTP", 22 :"SSH", 23: "telnet", 80: "http"}
2 |
3 | for k,v in port1.iteritems():
4 | print k," : ", v
--------------------------------------------------------------------------------
/Chapter05/forloopkey.py:
--------------------------------------------------------------------------------
1 | port1 = {21: "FTP", 22 :"SSH", 23: "telnet", 80: "http"}
2 |
3 | for each in port1:
4 | print each
--------------------------------------------------------------------------------
/Chapter05/has_key1.py:
--------------------------------------------------------------------------------
1 | port1 = {80: 'http', 18: None, 19: 'Unknown', 22: 'SSH', 23: 'Telnet'}
2 | if port1.has_key(80):
3 | print port1[80]
4 |
--------------------------------------------------------------------------------
/Chapter05/inkey.py:
--------------------------------------------------------------------------------
1 | port1 = {21: "FTP", 22 :"SSH", 23: "telnet", 80: "http"}
2 | key = int(raw_input("Enter the key "))
3 | if key in port1:
4 | print "YES"
5 | else :
6 | print "NO"
--------------------------------------------------------------------------------
/Chapter05/onelineexcercis1.py:
--------------------------------------------------------------------------------
1 | list1 = [1,2,3,4,5]
2 | list2 = ["a", "b", "c","d", "e"]
3 |
4 | dict1 = dict([k for k in zip(list1,list2)])
5 |
6 | print dict1
--------------------------------------------------------------------------------
/Chapter06/break_block.py:
--------------------------------------------------------------------------------
1 | attraction_in_Vienna = ['Stephen plaz', 'Maria-Hilfer strasse', 'Donau-insel', 'Vienna-Philharmonic']
2 | first = "Donau-insel"
3 | for each in attraction_in_Vienna:
4 | if(each == first):
5 | break
6 | print each
--------------------------------------------------------------------------------
/Chapter06/continue_statement.py:
--------------------------------------------------------------------------------
1 | movies = ["P.S I Love You", "Shutter Island", "Le Miserable Play", "King's Speech", "Forest Gump"]
2 |
3 | for each in movies:
4 | if (each== "Le Miserable Play"):
5 | continue
6 | print each
--------------------------------------------------------------------------------
/Chapter06/for_block_1.py:
--------------------------------------------------------------------------------
1 | for each in 'VIENNA PHILHARMONIC' :
2 | print each,
--------------------------------------------------------------------------------
/Chapter06/if_block.py:
--------------------------------------------------------------------------------
1 | password= raw_input("Enter the password\t")
2 | if password=="MI6":
3 | print "Welcome Mr. Bond."
--------------------------------------------------------------------------------
/Chapter06/if_elif_else_block.py:
--------------------------------------------------------------------------------
1 | num =float(raw_input("Enter the number:"))
2 | if num > 4:
3 | letter = 'A'
4 | elif num > 3:
5 | letter = 'B'
6 | elif num > 2:
7 | letter = 'C'
8 | else:
9 | letter = 'D'
10 | print "The Grade is " , letter
--------------------------------------------------------------------------------
/Chapter06/if_else_block.py:
--------------------------------------------------------------------------------
1 | password= raw_input("Enter the password\t")
2 | if password=="MI6":
3 | print "Welcome Mr. Bond."
4 | else:
5 | print "Access Denied."
--------------------------------------------------------------------------------
/Chapter06/nested_loops.py:
--------------------------------------------------------------------------------
1 | list1 = ["London","Paris","New York","Berlin"]
2 | for each in list1:
3 | str1 = each
4 | for s in str1:
5 | if (s =="o"):
6 | break
7 | print s,
8 | print "\n"
--------------------------------------------------------------------------------
/Chapter07/function_calling.py:
--------------------------------------------------------------------------------
1 | def helloWorld():
2 | """ This is Hello World Program"""
3 | print "You are in Hello World"
4 |
5 | helloWorld()
--------------------------------------------------------------------------------
/Chapter07/function_with_argument_n_return_value.py:
--------------------------------------------------------------------------------
1 | def sum(a, b):
2 | c = a+b
3 | return c
4 | x = 10
5 | y = 50
6 | print "Result of addition ", sum(x,y)
--------------------------------------------------------------------------------
/Chapter07/function_with_arguments.py:
--------------------------------------------------------------------------------
1 | def func(passArgument):
2 | print passArgument
3 | str = "hello all"
4 | func(str)
--------------------------------------------------------------------------------
/Chapter07/function_with_default_argument.py:
--------------------------------------------------------------------------------
1 | def info(name, age=50):
2 | print "Name", name
3 | print "age", age
4 | info("John", age=28)
5 | info("James")
--------------------------------------------------------------------------------
/Chapter07/function_with_key_value_pair_as_variable_length_argument.py:
--------------------------------------------------------------------------------
1 | def infocity(**var):
2 | print var
3 | for key, value in var.items():
4 | print "%s == %s" %(key,value)
5 |
6 |
7 | infocity(name="l4w", age = 20, city="Los Angeles")
8 | infocity(name="John",age=45, city="London", sex="male", medals=0)
--------------------------------------------------------------------------------
/Chapter07/function_with_no_argument.py:
--------------------------------------------------------------------------------
1 | def func(passArgument):
2 | print passArgument
3 | str = "hello all"
4 | func()
--------------------------------------------------------------------------------
/Chapter07/function_with_variable_length.py:
--------------------------------------------------------------------------------
1 | def variable_argument( var1, *vari):
2 | print "Out-put is",var1
3 | for var in vari:
4 | print var
5 | variable_argument(60)
6 | variable_argument(100,90,40,50,60)
--------------------------------------------------------------------------------
/Chapter07/global_variable.py:
--------------------------------------------------------------------------------
1 | def func():
2 | global k
3 | k=k+7
4 | print "variable k is now global",k
5 | k=10
6 | func()
7 | print "Accessing the value of k outside the function",k
--------------------------------------------------------------------------------
/Chapter07/pass_by_ref_vs_value1.py:
--------------------------------------------------------------------------------
1 | def pass_ref(list1):
2 | list1.extend([23,89])
3 | print "list inside the function: ",list1
4 | list1 = [12,67,90]
5 | print "list before pass", list1
6 | pass_ref(list1)
7 | print "list outside the function", list1
--------------------------------------------------------------------------------
/Chapter07/pass_by_ref_vs_value2.py:
--------------------------------------------------------------------------------
1 | def func(a):
2 | a=a+4
3 | print "Inside the function", a
4 | a= 10
5 | func(a)
6 | print "Outside the function", a
--------------------------------------------------------------------------------
/Chapter07/variable_scope.py:
--------------------------------------------------------------------------------
1 | def func():
2 | a =12
3 | print '''Inside the function the value of
4 | a is acting as local variable''', a
5 | a= 10
6 | func()
7 | print '''Outside function the value of a is
8 | acting as global variable''',a
--------------------------------------------------------------------------------
/Chapter07/variable_scope1.py:
--------------------------------------------------------------------------------
1 | def func():
2 | a =12
3 | print "a inside the function is the local variable",a
4 | func()
5 | print "Trying to access the local variable outside the function.",a
--------------------------------------------------------------------------------
/Chapter07/variable_scope2.py:
--------------------------------------------------------------------------------
1 | k = 4
2 |
3 | def main():
4 | list1 = []
5 |
6 | def add():
7 | for x in xrange(k):
8 | list1.append(x)
9 | print list1
10 |
11 | add()
12 |
13 | main()
--------------------------------------------------------------------------------
/Chapter08/alice1.py:
--------------------------------------------------------------------------------
1 | import myprog
2 | num = 10
3 | total = num+myprog.sum1(23,12)
4 | print "Alice total is ", total
5 |
--------------------------------------------------------------------------------
/Chapter08/mod1.py:
--------------------------------------------------------------------------------
1 | import module1
2 | x = 12
3 | y = 34
4 | print "Sum is ", module1.sum1(x,y)
5 | print "Multiple is ", module1.mul1(x,y)
--------------------------------------------------------------------------------
/Chapter08/mod2.py:
--------------------------------------------------------------------------------
1 | import module1 as md
2 | x = 12
3 | y = 34
4 | print "Sum is ", md.sum1(x,y)
5 | print "Multiple is ", md.mul1(x,y)
--------------------------------------------------------------------------------
/Chapter08/mod3.py:
--------------------------------------------------------------------------------
1 | from module1 import sum1
2 | x = 12
3 | y = 34
4 | print "Sum is ", sum1(x,y)
5 |
--------------------------------------------------------------------------------
/Chapter08/mod4.py:
--------------------------------------------------------------------------------
1 | from module1 import *
2 | from module2 import *
3 | x = 36
4 | y = 12
5 | print "Sum is ", sum1(x,y)
6 | print "Substraction is ", sub1(x,y)
7 | print "after divide ", divide1(x,y)
8 | print "Multiplication is ", mul1(x,y)
--------------------------------------------------------------------------------
/Chapter08/mod5.py:
--------------------------------------------------------------------------------
1 | import module1
2 | print dir(module1)
--------------------------------------------------------------------------------
/Chapter08/module1.py:
--------------------------------------------------------------------------------
1 | def sum1(a,b):
2 | c = a+b
3 | return c
4 |
5 | def mul1(a,b):
6 | c = a*b
7 | return c
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Chapter08/module1.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Learn-Python-in-7-Days/c852dc86008495faa0a037e361f2db6182147778/Chapter08/module1.pyc
--------------------------------------------------------------------------------
/Chapter08/module2.py:
--------------------------------------------------------------------------------
1 | def sub1(a,b):
2 | c = a-b
3 | return c
4 |
5 | def divide1(a,b):
6 | c = a/b
7 | return c
--------------------------------------------------------------------------------
/Chapter08/module2.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Learn-Python-in-7-Days/c852dc86008495faa0a037e361f2db6182147778/Chapter08/module2.pyc
--------------------------------------------------------------------------------
/Chapter08/myprog.py:
--------------------------------------------------------------------------------
1 | def sum1(a,b):
2 | c = a+b
3 | return c
4 |
5 | print "name is ", __name__
6 |
7 | if __name__ == '__main__' :
8 | print "Sum is ", sum1(3,6)
--------------------------------------------------------------------------------
/Chapter08/myprog.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Learn-Python-in-7-Days/c852dc86008495faa0a037e361f2db6182147778/Chapter08/myprog.pyc
--------------------------------------------------------------------------------
/Chapter08/sound_conversion/__init__.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Learn-Python-in-7-Days/c852dc86008495faa0a037e361f2db6182147778/Chapter08/sound_conversion/__init__.pyc
--------------------------------------------------------------------------------
/Chapter08/sound_conversion/rectomp3.py:
--------------------------------------------------------------------------------
1 | #Written by Mohit
2 | def rec2mp3():
3 | """
4 | Converions code
5 | """
6 | return "recording voice converted to Mp3"
--------------------------------------------------------------------------------
/Chapter08/sound_conversion/rectomp3.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Learn-Python-in-7-Days/c852dc86008495faa0a037e361f2db6182147778/Chapter08/sound_conversion/rectomp3.pyc
--------------------------------------------------------------------------------
/Chapter08/sound_conversion/rectowav.py:
--------------------------------------------------------------------------------
1 | #Written by Bhaskar
2 | def rec2wav():
3 | """
4 | Converions code
5 | """
6 | return"recording voice converted to wav"
--------------------------------------------------------------------------------
/Chapter08/sound_conversion/rectowma.py:
--------------------------------------------------------------------------------
1 | #Written by Denim
2 | def rec2wma():
3 | """
4 | Converions code
5 | """
6 | return "recording voice converted to wma"
--------------------------------------------------------------------------------
/Chapter08/sound_conversion/rectowma.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Learn-Python-in-7-Days/c852dc86008495faa0a037e361f2db6182147778/Chapter08/sound_conversion/rectowma.pyc
--------------------------------------------------------------------------------
/Chapter08/voice_changer.py:
--------------------------------------------------------------------------------
1 | import sys
2 | sys.path
3 | sys.path.append(F:\project_7days\modulepack\programs\sound_conversion)
4 |
5 | from sound_conversion import rectomp3
6 | from sound_conversion.rectowma import rec2wma
7 |
8 |
9 |
10 | print rectomp3.rec2mp3()
11 | print rec2wma()
--------------------------------------------------------------------------------
/Chapter09/batman.txt:
--------------------------------------------------------------------------------
1 | Bruce Wayne: People are dying, Alfred
2 | What would you have me do?
3 | Alfred Pennyworth: Endure, Master Wayne.
4 | Take it. They'll hate you for it,
5 | but that's the point of Batman,
6 | he can be the outcast.
7 | He can make the choice that no one else can make,
8 | the right choice.
9 | The Batman didn't murder Harvey Dent.
--------------------------------------------------------------------------------
/Chapter09/calc.py:
--------------------------------------------------------------------------------
1 |
2 | def sum1(a,b):
3 | try:
4 | c = a+b
5 | return c
6 | except :
7 | print "Error in sum1 function"
8 |
9 | def divide(a,b):
10 | try:
11 | c = a/b
12 | return c
13 | except :
14 | print "Error in divide function"
15 | print divide(10,0)
16 | print sum1(10,0)
--------------------------------------------------------------------------------
/Chapter09/divide1.py:
--------------------------------------------------------------------------------
1 | def divide1():
2 | try:
3 | num = int(raw_input("Enter the number "))
4 | c = 45/num
5 | print c
6 | except ValueError :
7 | print "Value is not int type"
8 | except ZeroDivisionError :
9 | print "Don't use zero"
10 | else:
11 | print "result is ",c
12 |
13 | divide1()
--------------------------------------------------------------------------------
/Chapter09/divied.py:
--------------------------------------------------------------------------------
1 | def divide1():
2 | num = int(raw_input("Enter the number "))
3 | c = 45/num
4 | print c
5 | divide1()
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Chapter09/emp1.dat:
--------------------------------------------------------------------------------
1 | (lp1
2 | S'mohit'
3 | p2
4 | aS'bhaskar'
5 | p3
6 | aS'manish'
7 | p4
8 | a.(lp1
9 | S'Python'
10 | p2
11 | ag2
12 | aS'Java'
13 | p3
14 | a.
--------------------------------------------------------------------------------
/Chapter09/emp2.dat:
--------------------------------------------------------------------------------
1 | (dp0
2 | S'skill'
3 | p1
4 | (lp2
5 | S'Python'
6 | p3
7 | aS'Data Analytic'
8 | p4
9 | aS'Information Security'
10 | p5
11 | aS'SAP'
12 | p6
13 | asS'name'
14 | p7
15 | (lp8
16 | S'Mohit'
17 | p9
18 | aS'Ravender'
19 | p10
20 | aS'Himmat'
21 | p11
22 | aS'Robbin'
23 | p12
24 | as.
--------------------------------------------------------------------------------
/Chapter09/exceptiontype.py:
--------------------------------------------------------------------------------
1 | try:
2 | num = int(raw_input("Enter the number "))
3 | re = 100/num
4 | print re
5 | except Exception as e :
6 | print e, type(e)
7 |
--------------------------------------------------------------------------------
/Chapter09/filecpickle1.py:
--------------------------------------------------------------------------------
1 | import cPickle as pickle
2 | name = ["mohit","bhaskar", "manish"]
3 | skill = ["Python", "Python", "Java"]
4 | pickle_file = open("emp1.dat","w")
5 | pickle.dump(name,pickle_file)
6 | pickle.dump(skill,pickle_file)
7 | pickle_file.close()
--------------------------------------------------------------------------------
/Chapter09/filepickle1.py:
--------------------------------------------------------------------------------
1 | import pickle
2 | name = ["mohit","bhaskar", "manish"]
3 | skill = ["Python", "Python", "Java"]
4 | pickle_file = open("emp1.dat","w")
5 | pickle.dump(name,pickle_file)
6 | pickle.dump(skill,pickle_file)
7 | pickle_file.close()
--------------------------------------------------------------------------------
/Chapter09/filepickle2.py:
--------------------------------------------------------------------------------
1 | import pickle
2 | pickle_file = open("emp1.dat",'r')
3 | name_list = pickle.load(pickle_file)
4 | skill_list =pickle.load(pickle_file)
5 | print name_list ,"\n", skill_list
--------------------------------------------------------------------------------
/Chapter09/filepickle3.py:
--------------------------------------------------------------------------------
1 | import pickle
2 | pickle_file = open("emp2.dat",'w')
3 | leapx_team = {
4 | 'name' : ["Mohit", "Ravender", "Himmat", "Robbin"],
5 | 'skill' : ["Python","Data Analytic", "Information Security", "SAP"]
6 | }
7 | pickle.dump(leapx_team,pickle_file)
8 | pickle_file.close()
--------------------------------------------------------------------------------
/Chapter09/filepickle4.py:
--------------------------------------------------------------------------------
1 | import pickle
2 | pickle_file = open("emp2.dat",'r')
3 | all_data = pickle.load(pickle_file)
4 | print all_data["skill"]
5 | print all_data["name"]
6 |
--------------------------------------------------------------------------------
/Chapter09/filewrite1.py:
--------------------------------------------------------------------------------
1 | file_input = open("motivation.txt",'w')
2 | file_input.write("Never give up")
3 | file_input.write("\nRise above hate")
4 | file_input.write("\nNo body remember second place")
5 | file_input.close()
--------------------------------------------------------------------------------
/Chapter09/filewrite2.py:
--------------------------------------------------------------------------------
1 | file_input = open("motivation.txt",'w')
2 | file_input.write("Never give up \nRise above hate \nNo body remember second place")
3 | file_input.close()
--------------------------------------------------------------------------------
/Chapter09/filewritea.py:
--------------------------------------------------------------------------------
1 | file_input = open("newmotivation.txt",'a')
2 | file_input.write("Never give up")
3 | file_input.write("\nRise above hate")
4 | file_input.write("\nNo body remember second place")
5 | file_input.close()
--------------------------------------------------------------------------------
/Chapter09/filewritea1.py:
--------------------------------------------------------------------------------
1 | file_input = open("newmotivation.txt",'a')
2 | file_input.write("\nBlood sweat and respect")
3 | file_input.write("\nThe first two you give")
4 | file_input.write("\nThe last you earn")
5 | file_input.write("\nGive it Earn it")
6 | file_input.close()
--------------------------------------------------------------------------------
/Chapter09/filewriteline.py:
--------------------------------------------------------------------------------
1 | list1 = ["Blood sweat and respect\n",
2 | "The first two you give\n"
3 | "The last you earn\n"
4 | "Give it Earn it"]
5 | text_file = open("wwerockquotes.txt", 'w')
6 | text_file.writelines(list1)
7 | text_file.close()
--------------------------------------------------------------------------------
/Chapter09/finally1.py:
--------------------------------------------------------------------------------
1 | try:
2 | num = int(raw_input("Enter the number "))
3 | re = 100/num
4 | except:
5 | print "Something is wrong"
6 | else:
7 | print "result is ",re
8 | finally :
9 | print "finally program ends"
--------------------------------------------------------------------------------
/Chapter09/findword.py:
--------------------------------------------------------------------------------
1 | word = raw_input("Enter the word ")
2 | word = word.lower()
3 | file_txt = open("batman.txt", "r")
4 |
5 | count = 0
6 | for each in file_txt:
7 | if word in each.lower():
8 | count = count+1
9 |
10 | print "The ", word ," occured ",count, " times"
11 |
--------------------------------------------------------------------------------
/Chapter09/motivation.txt:
--------------------------------------------------------------------------------
1 | Never give up
2 | Rise above hate
3 | No body remember second place
--------------------------------------------------------------------------------
/Chapter09/newmotivation.txt:
--------------------------------------------------------------------------------
1 | Never give up
2 | Rise above hate
3 | No body remember second place
4 | Blood sweat and respect
5 | The first two you give
6 | The last you earn
7 | Give it Earn it
--------------------------------------------------------------------------------
/Chapter09/readcount1.py:
--------------------------------------------------------------------------------
1 | file_input = open("sample1.txt",'r')
2 | print file_input.read(20)
3 | print file_input.read(15)
4 | print file_input.read(10)
5 | file_input.close()
--------------------------------------------------------------------------------
/Chapter09/readfile.py:
--------------------------------------------------------------------------------
1 | file_input = open("sample1.txt",'r')
2 | all_read = file_input.read()
3 | print all_read
4 | file_input.close()
--------------------------------------------------------------------------------
/Chapter09/readfileforloop.py:
--------------------------------------------------------------------------------
1 | file_input = open("sample1.txt",'r')
2 | for line in file_input:
3 | print line
--------------------------------------------------------------------------------
/Chapter09/readline1.py:
--------------------------------------------------------------------------------
1 | file_input = open("sample1.txt",'r')
2 | print file_input.readline()
3 | print file_input.readline()
4 | print file_input.readline()
5 | file_input.close()
--------------------------------------------------------------------------------
/Chapter09/readlinecount.py:
--------------------------------------------------------------------------------
1 | file_input = open("sample1.txt",'r')
2 | print file_input.readline(100)
3 | print file_input.readline(20)
4 | file_input.close()
--------------------------------------------------------------------------------
/Chapter09/readlines1.py:
--------------------------------------------------------------------------------
1 | file_input = open("sample1.txt",'r')
2 | print file_input.readlines()
3 | file_input.close()
--------------------------------------------------------------------------------
/Chapter09/sample1.txt:
--------------------------------------------------------------------------------
1 | Never give upRise above hateNo body remember second place
--------------------------------------------------------------------------------
/Chapter09/userdefined1.py:
--------------------------------------------------------------------------------
1 | class MyException(Exception):
2 | def __init__(self, value):
3 | self.value = value
4 | def __str__(self):
5 | return (self.value)
6 | try:
7 | num = raw_input("Enter the number : ")
8 | if num == '2':
9 | raise MyException("ohh")
10 | else :
11 | print "number is not 2"
12 | except MyException :
13 | print "My exception occurred"
--------------------------------------------------------------------------------
/Chapter09/userdefined2.py:
--------------------------------------------------------------------------------
1 | class MyException(Exception):
2 | def __init__(self, value):
3 | self.value = value
4 | def __str__(self):
5 | return (self.value)
6 | try:
7 | num = raw_input("Enter the number : ")
8 | if num == '2':
9 | raise MyException("ohh")
10 | else :
11 | print "number is not 2"
12 | except IOError:
13 | print "My exception occurred"
--------------------------------------------------------------------------------
/Chapter09/wwerockquotes.txt:
--------------------------------------------------------------------------------
1 | Blood sweat and respect
2 | The first two you give
3 | The last you earn
4 | Give it Earn it
--------------------------------------------------------------------------------
/Chapter10/Counter_input.txt:
--------------------------------------------------------------------------------
1 | Hello this example is for Counter. Here we will check the frequency of letters.
2 | This is going to be the toughest test for the Counter.
--------------------------------------------------------------------------------
/Chapter10/default_dict_example.py:
--------------------------------------------------------------------------------
1 | from collections import defaultdict
2 |
3 | def func():
4 | return "Cricket"
5 |
6 | game = defaultdict(func)
7 |
8 | game["A"]= "Football"
9 | game["B"] = "Badminton"
10 |
11 | print game
12 | print game["A"]
13 | print game["B"]
14 | print game["C"]
--------------------------------------------------------------------------------
/Chapter10/default_dict_example3.py:
--------------------------------------------------------------------------------
1 | from collections import defaultdict
2 |
3 | game = defaultdict(int)
4 |
5 | game["A"]= "Football"
6 | game["B"] = "Badminton"
7 |
8 | print game
9 | print game["A"]
10 | print game["B"]
11 | print game["C"]
--------------------------------------------------------------------------------
/Chapter10/default_dict_example4.py:
--------------------------------------------------------------------------------
1 | from collections import defaultdict
2 |
3 | game = defaultdict(int)
4 |
5 | list1 = ['cricket', 'badminton', 'hockey' 'rugby', 'golf', 'baseball' , 'football']
6 |
7 | for each in list1:
8 | game[each]= game[each]+1
9 |
10 | print game
--------------------------------------------------------------------------------
/Chapter10/default_dict_list_of_tuples.py:
--------------------------------------------------------------------------------
1 | from collections import defaultdict
2 |
3 | game = defaultdict(list)
4 |
5 | tuple_list_county = [('US', 'Visconsin'), ('Germany', 'Bavaria'), ('UK', 'Bradfordshire'), ('India', 'punjab'), ('China', 'Shandong'), ('Canada', 'Nova Scotia')]
6 |
7 | print game["any_value"]
8 |
9 | for k,v in tuple_list_county:
10 | game[k].append(v)
11 |
12 | print game
--------------------------------------------------------------------------------
/Chapter10/default_dict_with_lambda.py:
--------------------------------------------------------------------------------
1 | from collections import defaultdict
2 | game = defaultdict(lambda : "Cricket")
3 |
4 | game["A"]= "Football"
5 | game["B"] = "Badminton"
6 |
7 | print game
8 | print game["A"]
9 | print game["B"]
10 | print game["C"]
--------------------------------------------------------------------------------
/Chapter10/deque_consumption.py:
--------------------------------------------------------------------------------
1 | import collections
2 | d1 = collections.deque("abcdefghacmqdcb")
3 | print d1
4 | print "Poped element ",d1.pop()
5 | print d1
6 | print "Poped left element ",d1.popleft()
7 | print d1
--------------------------------------------------------------------------------
/Chapter10/deque_example.py:
--------------------------------------------------------------------------------
1 | import collections
2 |
3 | de = collections.deque('India')
4 | print 'deque:', de
5 | print 'Lenght :', len(de)
6 | print 'left end:', de[0]
7 | print 'right end:', de[-1]
8 |
9 | de.remove('a')
10 |
11 | print 'After removing:', de
--------------------------------------------------------------------------------
/Chapter10/deque_rotation.py:
--------------------------------------------------------------------------------
1 | import collections
2 |
3 | d = collections.deque(xrange(6))
4 | print "Normal queue", d
5 |
6 | d.rotate(2)
7 | print "\nRight rotation :", d
8 |
9 | d1 = collections.deque(xrange(6))
10 | d1.rotate(-2)
11 | print "\nleft rotation :", d1
--------------------------------------------------------------------------------
/Chapter10/named_tuple.py:
--------------------------------------------------------------------------------
1 | import collections
2 | employee = collections.namedtuple('emp','name, age, empid')
3 |
4 | record1 = employee("Hamilton", 28, 12365 )
5 |
6 | print "Record is ", record1
7 | print "name of employee is ", record1.name
8 | print "age of employee is ", record1.empid
9 |
10 | print "type is ",type(record1)
--------------------------------------------------------------------------------
/Chapter10/named_tuple_with_list_values.py:
--------------------------------------------------------------------------------
1 | import collections
2 | employee = collections.namedtuple('emp','name, age, empid')
3 | list1 = ['BOB', 21, 34567]
4 | record2 =employee._make(list1)
5 | print record2
6 | print "\n"
7 | print (record2._asdict())
--------------------------------------------------------------------------------
/Chapter10/ordered_vs_normal_dict.py:
--------------------------------------------------------------------------------
1 | import collections
2 | print 'Regular Dictionary'
3 | d = {}
4 | d['a']= 'SAS'
5 | d['b']= 'PYTHON'
6 | d['c']= 'R'
7 |
8 | for k,v in d.items():
9 | print k, ":",v
10 |
11 | print '\n Ordered dictionary'
12 |
13 | d1 = collections.OrderedDict()
14 | d1['a']= 'SAS'
15 | d1['b']= 'PYTHON'
16 | d1['c']= 'R'
17 |
18 | for k,v in d1.items():
19 | print k, ":",v
--------------------------------------------------------------------------------
/Chapter10/populating_deque.py:
--------------------------------------------------------------------------------
1 | import collections
2 | d1 = collections.deque("Google")
3 | print d1
4 | d1.extend('raj')
5 | print "after extend :\n", d1
6 | d1.append('hi')
7 | print "After append :\n",d1
8 |
9 | d1.extendleft("de")
10 | print "after extend left\n ", d1
11 |
12 | d1.appendleft("le")
13 | print "after append left\n ", d1
--------------------------------------------------------------------------------
/Chapter10/reading_text_file.py:
--------------------------------------------------------------------------------
1 | import collections
2 |
3 | co = collections.Counter()
4 | file_txt = open("Counter_input.txt","r")
5 | for line in file_txt:
6 | co.update(line.lower())
7 | print co
--------------------------------------------------------------------------------
/Chapter10/reading_text_file1.py:
--------------------------------------------------------------------------------
1 | import collections
2 |
3 | co = collections.Counter()
4 | file_txt = open("Counter_input.txt","r")
5 | for line in file_txt:
6 | co.update(line.lower())
7 |
8 | print "Most common:\n"
9 | for letter, count in co.most_common(5):
10 | print '%s: %7d' % (letter, count)
--------------------------------------------------------------------------------
/Chapter10/replacing_value_from_named_tuple.py:
--------------------------------------------------------------------------------
1 | import collections
2 | employee = collections.namedtuple('emp','name, age, empid')
3 |
4 | record1 = employee("Marina", 28, 12365 )
5 |
6 | print "Record is ", record1
7 | print "\n"
8 | print record1._replace(age= 25)
9 | print "\n"
10 | print "Record is ", record1
11 | print "\n"
12 | record1 = record1._replace(age= 25)
13 | print "Record is ", record1
14 |
--------------------------------------------------------------------------------
/Chapter10/set_operations_of_Counter.py:
--------------------------------------------------------------------------------
1 | import collections
2 |
3 | co1 = collections.Counter(['C','L','E','O','P','A','T','R','A'])
4 | co2 = collections.Counter('JULIUS CAESAR')
5 |
6 | print co1
7 | print co2
8 |
9 | print "addition \n",co1 + co2 # Prints addition of sets
10 | print "Subtraction\n", co1 - co2 # Prints substration of sets
11 |
12 | print "Union \n", co1 | co2 # Prints union of sets
13 | print "Intersection \n", co1 & co2 # Prints intersection of sets
--------------------------------------------------------------------------------
/Chapter10/sorting_ordered_dict.py:
--------------------------------------------------------------------------------
1 | import collections
2 | print '\n Order dictionary'
3 | d1 = collections.OrderedDict()
4 | d1['a']= 'SAS'
5 | d1['d']= 'PYTHON'
6 | d1['b']= 'JULIA'
7 | d1['f']= 'R'
8 | d1['c']= 'SPARK'
9 |
10 | for k,v in d1.items():
11 | print k, ":",v
12 | print '\n Sorted Order dictionary'
13 | dict = collections.OrderedDict(sorted(d1.items()))
14 |
15 | for k,v in dict.items():
16 | print k, ":",v
--------------------------------------------------------------------------------
/Chapter10/sorting_ordered_dict_based_on_values.py:
--------------------------------------------------------------------------------
1 | import collections
2 | print '\n Order dictionary'
3 | d1 = collections.OrderedDict()
4 | d1['a']= 'SAS'
5 | d1['d']= 'PYTHON'
6 | d1['b']= 'SAP HANNA'
7 | d1['f']= 'R'
8 | d1['c']= 'JULIA'
9 |
10 | for k,v in d1.items():
11 | print k, ":",v
12 | print '\n Sorted Order dictionary'
13 | dict = collections.OrderedDict(sorted(d1.items(), key=lambda (k,v): v))
14 |
15 | for k,v in dict.items():
16 | print k, ":",v
--------------------------------------------------------------------------------
/Chapter10/usage_of_counter.py:
--------------------------------------------------------------------------------
1 | import collections
2 |
3 | c = collections.Counter('King TutanKhamen was the youngest Pharoah')
4 | print c
5 | for letter in 'What a king?':
6 | print '%s : %d' % (letter, c[letter])
7 |
--------------------------------------------------------------------------------
/Chapter11/class1.py:
--------------------------------------------------------------------------------
1 | class Leapx_org():
2 | pass
3 |
4 | L_obj1 = Leapx_org()
5 | L_obj2 = Leapx_org()
6 |
7 | print (L_obj1)
8 | print (L_obj2)
9 |
--------------------------------------------------------------------------------
/Chapter11/class2.py:
--------------------------------------------------------------------------------
1 | class Leapx_org():
2 | pass
3 | L_obj1 = Leapx_org()
4 | L_obj2 = Leapx_org()
5 |
6 | L_obj1.f_name = "Mohit"
7 | L_obj1.L_name = "RAJ"
8 | L_obj1.pamount = "60000"
9 |
10 | L_obj2.f_name = "Ravender"
11 | L_obj2.L_name = "Dahiya"
12 | L_obj2.pamount = "70000"
13 |
14 | print L_obj1.f_name+ " "+ L_obj1.L_name
15 | print L_obj2.f_name+ " "+ L_obj2.L_name
16 |
--------------------------------------------------------------------------------
/Chapter11/classinheri1.py:
--------------------------------------------------------------------------------
1 | class Leapx_org():
2 | mul_num = 1.20
3 | count= 0
4 | def __init__(self,first,last,pay):
5 | self.f_name = first
6 | self.l_name = last
7 | self.pay_amt = pay
8 | self.full_name = first+" "+last
9 | Leapx_org.count = Leapx_org.count+1
10 |
11 | def make_email(self):
12 | return self.f_name+ "."+self.l_name+"@xyz.com"
13 |
14 | def incrementpay(self):
15 | self.pay_amt = int(self.pay_amt*self.mul_num)
16 | return self.pay_amt
17 |
18 | class instructor(Leapx_org):
19 | pass
20 |
21 | I_obj1 = instructor('mohit', 'RAJ', 60000)
22 | I_obj2 = instructor('Ravender', 'Dahiya',70000)
23 |
24 | print "number of employees ", instructor.count
25 |
26 | print I_obj1.make_email()
27 | print I_obj2.make_email()
28 |
29 | print (help(instructor))
30 |
--------------------------------------------------------------------------------
/Chapter11/classinheri2.py:
--------------------------------------------------------------------------------
1 | class Leapx_org():
2 | mul_num = 1.20
3 | count= 0
4 | def __init__(self,first,last,pay):
5 | self.f_name = first
6 | self.l_name = last
7 | self.pay_amt = pay
8 | self.full_name = first+" "+last
9 | Leapx_org.count = Leapx_org.count+1
10 |
11 | def make_email(self):
12 | return self.f_name+ "."+self.l_name+"@xyz.com"
13 |
14 | def incrementpay(self):
15 | self.pay_amt = int(self.pay_amt*self.mul_num)
16 | return self.pay_amt
17 |
18 | class instructor(Leapx_org):
19 | def __init__(self,first,last,pay, subject):
20 | Leapx_org.__init__(self,first,last,pay)
21 | self.subject = subject
22 |
23 | I_obj1 = instructor('mohit', 'RAJ', 60000, "Python")
24 | I_obj2 = instructor('Ravender', 'Dahiya',70000, "Data Analytic")
25 |
26 |
27 | print I_obj1.make_email()
28 | print I_obj1.subject
29 | print I_obj2.make_email()
30 | print I_obj2.subject
31 |
32 |
--------------------------------------------------------------------------------
/Chapter11/classinit.py:
--------------------------------------------------------------------------------
1 | class Leapx_org():
2 | def __init__(self,first,last,pay):
3 | self.f_name = first
4 | self.l_name = last
5 | self.pay_amt = pay
6 | self.full_name = first+" "+last
7 |
8 |
9 | L_obj1 = Leapx_org('mohit', 'RAJ', 60000)
10 | L_obj2 = Leapx_org('Ravender', 'Dahiya',70000)
11 |
12 | print L_obj1.full_name
13 | print L_obj2.full_name
--------------------------------------------------------------------------------
/Chapter11/classinstance1.py:
--------------------------------------------------------------------------------
1 | class Leapx_org():
2 | def __init__(self,first,last,pay):
3 | self.f_name = first
4 | self.l_name = last
5 | self.pay_amt = pay
6 | self.full_name = first+" "+last
7 |
8 | def make_email(self):
9 | return self.f_name+ "."+self.l_name+"@xyz.com"
10 |
11 | def incrementpay(self):
12 | self.pay_amt = int(self.pay_amt*1.20)
13 | return self.pay_amt
14 |
15 | L_obj1 = Leapx_org('mohit', 'RAJ', 60000)
16 | L_obj2 = Leapx_org('Ravender', 'Dahiya',70000)
17 |
18 | print L_obj1.pay_amt
19 | print L_obj1.incrementpay()
--------------------------------------------------------------------------------
/Chapter11/classinstance2.py:
--------------------------------------------------------------------------------
1 | class Leapx_org():
2 |
3 | mul_num = 1.20
4 | def __init__(self,first,last,pay):
5 | self.f_name = first
6 | self.l_name = last
7 | self.pay_amt = pay
8 | self.full_name = first+" "+last
9 |
10 | def make_email(self):
11 | return self.f_name+ "."+self.l_name+"@xyz.com"
12 |
13 | def incrementpay(self):
14 | self.pay_amt = int(self.pay_amt*self.mul_num)
15 | return self.pay_amt
16 |
17 | L_obj1 = Leapx_org('mohit', 'RAJ', 60000)
18 | L_obj2 = Leapx_org('Ravender', 'Dahiya',70000)
19 |
20 | print L_obj1.pay_amt
21 | print L_obj1.incrementpay()
22 |
23 | print L_obj1.mul_num
24 | print L_obj2.mul_num
25 | print Leapx_org.mul_num
26 |
27 |
--------------------------------------------------------------------------------
/Chapter11/classinstance3.py:
--------------------------------------------------------------------------------
1 | class Leapx_org():
2 |
3 | mul_num = 1.20
4 | def __init__(self,first,last,pay):
5 | self.f_name = first
6 | self.l_name = last
7 | self.pay_amt = pay
8 | self.full_name = first+" "+last
9 |
10 | def make_email(self):
11 | return self.f_name+ "."+self.l_name+"@xyz.com"
12 |
13 | def incrementpay(self):
14 | self.pay_amt = int(self.pay_amt*self.mul_num)
15 | return self.pay_amt
16 |
17 | L_obj1 = Leapx_org('mohit', 'RAJ', 60000)
18 | L_obj2 = Leapx_org('Ravender', 'Dahiya',70000)
19 |
20 | print "instance space ",L_obj1.__dict__
21 | print "class space ",Leapx_org.__dict__
22 |
--------------------------------------------------------------------------------
/Chapter11/classinstance4.py:
--------------------------------------------------------------------------------
1 | class Leapx_org():
2 |
3 | mul_num = 1.20
4 | def __init__(self,first,last,pay):
5 | self.f_name = first
6 | self.l_name = last
7 | self.pay_amt = pay
8 | self.full_name = first+" "+last
9 |
10 | def make_email(self):
11 | return self.f_name+ "."+self.l_name+"@xyz.com"
12 |
13 | def incrementpay(self):
14 | self.pay_amt = int(self.pay_amt*self.mul_num)
15 | return self.pay_amt
16 |
17 | L_obj1 = Leapx_org('mohit', 'RAJ', 60000)
18 | L_obj2 = Leapx_org('Ravender', 'Dahiya',70000)
19 |
20 | L_obj1.mul_num = 1.3
21 |
22 | print "instance space L_obj1 \n",L_obj1.__dict__
23 | print "\ninstance space L_obj2 \n",L_obj2.__dict__
24 | print "\nclass space \n",Leapx_org.__dict__
25 |
26 | print L_obj1.mul_num
27 | print L_obj2.mul_num
28 | print Leapx_org.mul_num
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Chapter11/classinstance5.py:
--------------------------------------------------------------------------------
1 | class Leapx_org():
2 | mul_num = 1.20
3 | count= 0
4 | def __init__(self,first,last,pay):
5 | self.f_name = first
6 | self.l_name = last
7 | self.pay_amt = pay
8 | self.full_name = first+" "+last
9 | Leapx_org.count = Leapx_org.count+1
10 | #self.count = self.count+1
11 | print self.count
12 | def make_email(self):
13 | return self.f_name+ "."+self.l_name+"@xyz.com"
14 |
15 | def incrementpay(self):
16 | self.pay_amt = int(self.pay_amt*self.mul_num)
17 | return self.pay_amt
18 |
19 | L_obj1 = Leapx_org('mohit', 'RAJ', 60000)
20 | L_obj2 = Leapx_org('Ravender', 'Dahiya',70000)
21 | L_obj2 = Leapx_org('Bhaskar', 'DAS',70000)
22 |
23 | print "Number of Employees are : ", Leapx_org.count
--------------------------------------------------------------------------------
/Chapter11/classinstance6.py:
--------------------------------------------------------------------------------
1 | class Leapx_org():
2 | def __init__(self,first,last,pay):
3 | self.f_name = first
4 | self.l_name = last
5 | self.pay_amt = pay
6 | self.full_name = first+" "+last
7 | def make_email(self):
8 | return self.f_name+ "."+self.l_name+"@xyz.com"
9 | def __str__(self):
10 | str1 = "instance belongs to "+self.full_name
11 | return str1
12 |
13 | L_obj1 = Leapx_org('mohit', 'RAJ',60000)
14 | print L_obj1
15 | print "\n"
16 | #print "Lenght is ",len(L_obj1)
--------------------------------------------------------------------------------
/Chapter11/classmethod1.py:
--------------------------------------------------------------------------------
1 | class Leapx_org():
2 | def __init__(self,first,last,pay):
3 | self.f_name = first
4 | self.l_name = last
5 | self.pay_amt = pay
6 | self.full_name = first+" "+last
7 |
8 | def make_email(self):
9 | return self.f_name+ "."+self.l_name+"@xyz.com"
10 |
11 | L_obj1 = Leapx_org('mohit', 'RAJ', 60000)
12 | L_obj2 = Leapx_org('Ravender', 'Dahiya',70000)
13 |
14 | print L_obj1.full_name
15 | print L_obj1.make_email()
16 |
17 | print L_obj2.full_name
18 | print L_obj2.make_email()
19 |
20 |
--------------------------------------------------------------------------------
/Chapter11/classmethod2.py:
--------------------------------------------------------------------------------
1 | class Leapx_org():
2 | def __init__(self,first,last,pay):
3 | self.f_name = first
4 | self.l_name = last
5 | self.pay_amt = pay
6 | self.full_name = first+" "+last
7 |
8 | def make_email():
9 | return self.f_name+ "."+self.l_name+"@xyz.com"
10 |
11 | L_obj1 = Leapx_org('mohit', 'RAJ', 60000)
12 | print L_obj1.make_email()
13 | print Leapx_org.make_email(L_obj1)
--------------------------------------------------------------------------------
/Chapter11/classmethod3.py:
--------------------------------------------------------------------------------
1 | class Leapx_org():
2 | def __init__(self,first,last,pay):
3 | self.f_name = first
4 | self.l_name = last
5 | self.pay_amt = pay
6 | self.full_name = first+" "+last
7 |
8 | def make_email(self):
9 | return self.f_name+ "."+self.l_name+"@xyz.com"
10 |
11 | L_obj1 = Leapx_org('mohit', 'RAJ', 60000)
12 | print L_obj1.make_email()
13 | print Leapx_org.make_email(L_obj1)
--------------------------------------------------------------------------------
/Chapter11/classmultilevel.py:
--------------------------------------------------------------------------------
1 | class A():
2 | def sum1(self,a,b):
3 | c = a+b
4 | return c
5 |
6 | class B(A):
7 | def sub1(self,a,b):
8 | c = a-b
9 | return c
10 |
11 | class C(B):
12 | pass
13 |
14 | c_obj = C()
15 | print "Sum is ", c_obj.sum1(12,4)
16 |
--------------------------------------------------------------------------------
/Chapter11/classmultiple.py:
--------------------------------------------------------------------------------
1 | class A():
2 | def sum1(self,a,b):
3 | c = a+b
4 | return c
5 |
6 | class B():
7 | def sub1(self,a,b):
8 | c = a-b
9 | return c
10 |
11 | class C(A,B):
12 | pass
13 |
14 | c_obj = C()
15 | print "Sum is ", c_obj.sum1(12,4)
16 | print "After substraction ",c_obj.sub1(45,5)
--------------------------------------------------------------------------------
/Chapter11/classoperator1.py:
--------------------------------------------------------------------------------
1 | class Leapx_org():
2 | def __init__(self,first,last,pay):
3 | self.f_name = first
4 | self.l_name = last
5 | self.pay_amt = pay
6 | self.full_name = first+" "+last
7 |
8 | def make_email(self):
9 | return self.f_name+ "."+self.l_name+"@xyz.com"
10 |
11 | L_obj1 = Leapx_org('mohit', 'RAJ', 60000)
12 | L_obj2 = Leapx_org('Ravender', 'Dahiya',70000)
13 |
14 | print L_obj1+L_obj2
--------------------------------------------------------------------------------
/Chapter11/classoperator2.py:
--------------------------------------------------------------------------------
1 | class Leapx_org():
2 | def __init__(self,first,last,pay):
3 | self.f_name = first
4 | self.l_name = last
5 | self.pay_amt = pay
6 | self.full_name = first+" "+last
7 |
8 | def make_email(self):
9 | return self.f_name+ "."+self.l_name+"@xyz.com"
10 |
11 | def __add__(self,other):
12 | result = self.pay_amt+ other.pay_amt
13 | return result
14 |
15 | L_obj1 = Leapx_org('mohit', 'RAJ', 60000)
16 | L_obj2 = Leapx_org('Ravender', 'Dahiya',70000)
17 |
18 | print L_obj1+L_obj2
--------------------------------------------------------------------------------
/Chapter11/classoperator3.py:
--------------------------------------------------------------------------------
1 | class Leapx_org():
2 | def __init__(self,first,last,pay):
3 | self.f_name = first
4 | self.l_name = last
5 | self.pay_amt = pay
6 | self.full_name = first+" "+last
7 | def make_email(self):
8 | return self.f_name+ "."+self.l_name+"@xyz.com"
9 | def __gt__(self,other):
10 | return self.pay_amt>=other.pay_amt
11 |
12 | L_obj1 = Leapx_org('mohit', 'RAJ',60000)
13 | L_obj2 = Leapx_org('Ravender', 'Dahiya',70000)
14 | print L_obj1>L_obj2
--------------------------------------------------------------------------------
/Chapter11/classoperator4.py:
--------------------------------------------------------------------------------
1 | class Leapx_org():
2 | def __init__(self,first,last,pay):
3 | self.f_name = first
4 | self.l_name = last
5 | self.pay_amt = pay
6 | self.full_name = first+" "+last
7 | def make_email(self):
8 | return self.f_name+ "."+self.l_name+"@xyz.com"
9 |
10 | L_obj1 = Leapx_org('mohit', 'RAJ',60000)
11 | print L_obj1
12 | print "\n"
13 | print "Lenght is ",len(L_obj1)
--------------------------------------------------------------------------------
/Chapter11/classoperator5.py:
--------------------------------------------------------------------------------
1 | class Leapx_org():
2 | def __init__(self,first,last,pay):
3 | self.f_name = first
4 | self.l_name = last
5 | self.pay_amt = pay
6 | self.full_name = first+" "+last
7 | def make_email(self):
8 | return self.f_name+ "."+self.l_name+"@xyz.com"
9 | def __str__(self):
10 | str1 = "instance belongs to "+self.full_name
11 | return str1
12 | def __len__(self):
13 | return len(self.f_name+self.l_name)
14 |
15 | L_obj1 = Leapx_org('mohit', 'RAJ',60000)
16 | print L_obj1
17 | print "\n"
18 | print "Lenght is ",len(L_obj1)
--------------------------------------------------------------------------------
/Chapter11/classover1.py:
--------------------------------------------------------------------------------
1 | class A():
2 | def sum1(self,a,b):
3 | print "In class A"
4 | c = a+b
5 | return c
6 |
7 | class B(A):
8 | f = 7
9 | def sum1(self,a,b):
10 | print "In class B"
11 | c= a*a+b*b
12 | return c
13 | b_obj = B()
14 |
15 | print B.__dict__
16 | print b_obj.sum1(4,5)
17 |
18 |
--------------------------------------------------------------------------------
/Chapter11/methodclass1.py:
--------------------------------------------------------------------------------
1 | class Leapx_org():
2 | mul_num = 1.20
3 | def __init__(self,first,last,pay):
4 | self.f_name = first
5 | self.l_name = last
6 | self.pay_amt = pay
7 | self.full_name = first+" "+last
8 | def make_email(self):
9 | return self.f_name+ "."+self.l_name+"@xyz.com"
10 | def incrementpay(self):
11 | self.pay_amt = int(self.pay_amt*self.mul_num)
12 | return self.pay_amt
13 | @classmethod
14 | def mul_num_set(cls, amt):
15 | cls.mul_num=amt
16 |
17 |
18 | L_obj1 = Leapx_org('mohit', 'RAJ', 60000)
19 | L_obj2 = Leapx_org('Ravender', 'Dahiya',70000)
20 | L_obj1.mul_num_set(1.40)
21 | #Leapx_org.mul_num_set(1.40)
22 | print L_obj1.mul_num
23 | print L_obj2.mul_num
--------------------------------------------------------------------------------
/Chapter11/private1.py:
--------------------------------------------------------------------------------
1 | class A:
2 | __amount = 45
3 | def __info(self):
4 | print "I am in Class A"
5 | def hello(self):
6 | print "Amount is ",A.__amount
7 | a = A()
8 | a.hello()
9 | a._A__info()
10 | print a._A__amount
11 |
12 |
--------------------------------------------------------------------------------
/Chapter11/staticmethod1.py:
--------------------------------------------------------------------------------
1 | class Leapx_org():
2 | mul_num = 1.20
3 | mul_num2 = 1.30
4 | def __init__(self,first,last,pay):
5 | self.f_name = first
6 | self.l_name = last
7 | self.pay_amt = pay
8 | self.full_name = first+" "+last
9 | @staticmethod
10 | def check_amt(amt):
11 | if amt <50000:
12 | return True
13 | else :
14 | return False
15 | def incrementpay(self):
16 | if self.check_amt(self.pay_amt):
17 | self.pay_amt = int(self.pay_amt*self.mul_num2)
18 | else :
19 | self.pay_amt = int(self.pay_amt*self.mul_num)
20 | return self.pay_amt
21 |
22 |
23 |
24 | L_obj1 = Leapx_org('mohit', 'RAJ', 40000)
25 | L_obj2 = Leapx_org('Ravender', 'Dahiya',70000)
26 | L_obj1.incrementpay()
27 | L_obj2.incrementpay()
28 | print L_obj1.pay_amt
29 | print L_obj2.pay_amt
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Packt
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ## $5 Tech Unlocked 2021!
5 | [Buy and download this Book for only $5 on PacktPub.com](https://www.packtpub.com/product/learn-python-in-7-days/9781787288386)
6 | -----
7 | *The $5 campaign runs from __December 15th 2020__ to __January 13th 2021.__*
8 |
9 | # Learn Python in 7 Days
10 | This is the code repository for [Learn Python in 7 Days](https://www.packtpub.com/application-development/learn-python-7-days?utm_source=github&utm_medium=repository&utm_campaign=9781787288386), published by [Packt](https://www.packtpub.com/?utm_source=github). It contains all the supporting project files necessary to work through the book from start to finish.
11 | ## About the Book
12 | Python was initially developed by Guido Von Rossum as a fun project and was named after his favorite show Monty Python's Flying Circus. It was developed in 1991, but it started becoming popular around 2008. A major contributor to this popularity was Google, which has developed a number of platforms using Python. Recently, Python has been popularized by cloud, DevOps, data science, data analytics, machine learning, and natural language processing. With more and more data harvesting and data processing, people want to get into new types of job roles, which require basic programming skills, and Python perfectly suits all the categories of job work. Learn Python in 7 days has been designed to give such people an easy way to learn and master the basics of Python in 7 days. The book covers the basic and necessary concepts that are required to understand the working of the Python language. The book is for all types of readers and learners. It also acts as a refresher for experienced people. We believe that we have covered as much as possible for making it a book to be finished in seven days; however, we believe that merely reading the book is not sufficient to master programming skills. It will take more than that to achieve mastery. We hope you enjoy reading the book and use it as a good learning book.
13 | ## Instructions and Navigation
14 | All of the code is organized into folders. Each folder starts with a number followed by the application name. For example, Chapter02.
15 |
16 |
17 |
18 | The code will look like the following:
19 | ```
20 | print "Name Marks Age"
21 | print ( "%s %14.2f %11d" % ("John Doe", 80.67, 27))
22 | print ( "%s %12.2f %11d" %("Bhaskar" ,76.901, 27))
23 | print ( "%s %3.2f %11d" %("Mohit", 56.98, 25))
24 | ```
25 |
26 | For this book, you need to install Python 2.7x version on your machine, along with a simple text editor (Notepad or Notepad++). All the examples are meant to be run on the Python 2.7 version and will not work in Python 3.x versions.
27 |
28 | ## Related Products
29 | * [Learning scikit-learn: Machine Learning in Python](https://www.packtpub.com/big-data-and-business-intelligence/learning-scikit-learn-machine-learning-python?utm_source=github&utm_medium=repository&utm_campaign=9781783281930)
30 |
31 | * [Python: Real World Machine Learning](https://www.packtpub.com/big-data-and-business-intelligence/python-real-world-machine-learning?utm_source=github&utm_medium=repository&utm_campaign=9781787123212)
32 |
33 | * [Kivy: Interactive Applications in Python](https://www.packtpub.com/application-development/kivy-interactive-applications-python?utm_source=github&utm_medium=repository&utm_campaign=9781783281596)
34 |
35 | ### Download a free PDF
36 |
37 | If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.
38 |