Python Complete Course
Python Complete Course
BY
NANDAKUMAR P
TRA, VIT
COURSE CONTENT
1. INTRODUCTION TO PYTHON
2. VARIABLE DECLARATION
3. CONDITION EXECUTION
4. PYTHON FUNCTIONS
5. PYTHON MODULES
6. SEQUENCES
7. PYTHON STRINGS, SETS AND DICTIONARY
8. PYTHON FILE I/O
9. PYTHON ERRORS AND BUILT-IN EXCEPTIONS
10. PYTHON NAMESPACE AND SCOPE
11. PYTHON OBJECTS AND CLASS
12. PYTHON INHERITANCE
13. PYTHON – NETWORK PROGRAMMING
14. PYTHON – MULTITHREADING PROGRAMMING
CHAPTER 1: INTRODUCTION TO PYTHON
Python is a
Python Features:
Easy-to-learn
Easy-to-read
Easy-to-maintain
A broad standard library
Interactive mode
Portable
Extendable
Databases
GUI Programming
Scalable
CHAPTER 1CONTINUES…
Two ways:
1. Immediate mode
2. Script mode
Variables Declaration
Python Statement, Indentation and Comments
Python List (Ordered sequences of items)
Python Strings (Sequence of Unicode characters)
Python Set (Unordered collection of Unique Items)
Python Dictionary (Unordered collection of key-value pairs)
Conversion between data types
Python Input, Output and Import
Python Operators
CHAPTER 2 CONTINUES… - VARIABLES
The operand to the left of the = operator is the name of the variable and
the operand to the right of the = operator is the value stored in the
variable.
Example:
counter = 100 # An integer assignment
print counter
print miles
print name
CHAPTER 2 CONTINUES… - LIST
A list contains items separated by commas and enclosed within square brackets ([]).
The values stored in a list can be accessed using the slice operator ([ ] and [:]) with
indexes starting at 0 in the beginning of the list and working their way to end -1.
The plus (+) sign is the list concatenation operator, and the asterisk (*) is the repetition
operator.
Example:
The main differences between lists and tuples are: Lists are enclosed in brackets ( [ ] ) and
their elements and size can be changed, while tuples are enclosed in parentheses ( ( ) ) and
cannot be updated.
Example:
print tuple[1:3] # Prints elements of the tuple starting from 2nd till 3rd
print tuple[2:] # Prints elements of the tuple starting from 3rd element
Subsets of strings can be taken using the slice operator ([ ] and [:] ) with indexes starting
at 0 in the beginning of the string and working their way from -1 at the end.
The plus (+) sign is the string concatenation operator and the asterisk (*) is the repetition
operator.
Example:
str = 'Hello World!'
print str # Prints complete string
print str[0] # Prints first character of the string
print str[2:5] # Prints characters starting from 3rd to 5th
print str[2:] # Prints string starting from 3rd character
print str * 2 # Prints string two times
print str + "TEST" # Prints concatenated string
CHAPTER 2 CONTINUES… - SETS
Example:
# Different types of sets in Python
# set of integers
my_set = {1, 2, 3}
print(my_set)
Each key is separated from its value by a colon (:), the items are
separated by commas, and the whole thing is enclosed in curly braces.
An empty dictionary without any items is written with just two curly
braces, like this: {}.
Keys are unique within a dictionary while values may not be.
The values of a dictionary can be of any type, but the keys must be of an
immutable data type such as strings, numbers, or tuples.
Example:
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
print "dict['Name']: ", dict['Name']
print "dict['Age']: ", dict['Age']
CHAPTER 2 CONTINUES… - OPERATORS
Types of Operator
Logical Operators
and (Logical AND)
or (Logical OR)
not Logical NOT
Membership Operators
in
not in
Identity Operators
is
is not
CHAPTER 2 CONTINUES… - IMPORT
Python import
Module – is a file containing python definitions and statements
Python module have a filename and end with the extension .py
Example:
import math
print(math.pi)
from math import pi
pi
CHAPTER 3 – CONDITION EXECUTION
The if statement contains a logical expression using which data is compared and
a decision is made based on the result of the comparison.
Syntax (If)
if expression:
statement(s)
If the boolean expression evaluates to TRUE, then the block of statement(s)
inside the if statement is executed.
If boolean expression evaluates to FALSE, then the first set of code after the
end of the if statement(s) is executed.
CHAPTER 3 CONTINUES…. CONDITION EXECUTION
Example:
var1 = 100
if var1:
print ("1 - Got a true expression value“)
print (var1)
var2 = 0
if var2:
print ("2 - Got a true expression value“)
print (var2)
print ("Good bye!“)
CHAPTER 3 CONTINUES…. CONDITION EXECUTION
Example
var1 = 100
if var1:
print ("1 - Got a true expression value“)
print var1
else:
print ("1 - Got a false expression value“)
print (var1)
var2 = 0
if var2:
print ("2 - Got a true expression value“)
print (var2)
else:
print ("2 - Got a false expression value“)
print (var2)
Example:
if expression1:
var = 100
statement(s) if var < 200:
if expression2: print "Expression value is less than 200"
statement(s) if var == 150:
print "Which is 150"
elif expression3: elif var == 100:
statement(s) print "Which is 100"
elif expression4: elif var == 50:
statement(s) print "Which is 50"
elif var < 50:
else: print "Expression value is less than 50"
statement(s) else:
else: print "Could not find true expression"
statement(s)
print "Good bye!"
CHAPTER 3 CONTINUES…. CONDITION EXECUTION
count = 0
while (count < 9):
print ('The count is:', count)
count = count + 1
It has the ability to iterate over the items of any sequence, such as a list or a
string.
Syntax (For Loop)
for iterating_var in sequence:
statements(s)
Example:
Python programming language allows to use one loop inside another loop.
Syntax (Nested Loop)
For Loop
for iterating_var in sequence:
Example:
for iterating_var in sequence:
statements(s) i=2
statements(s) while(i < 100):
While Loop
j=2
while(j <= (i/j)):
while expression:
if not(i%j): break
while expression: j=j+1
statement(s) if (j > i/j) : print (i, " is prime“)
statement(s) i=i+1
break
Example: It terminates the current loop
continue and resumes execution at the next
pass statement, just like the traditional break
statement in C.
break
continue
pass
parentheses.
You can also define parameters inside these parentheses.
The code block within every function starts with a colon (:) and is indented.
Syntax:
Calling a Function:
def printme( str ):
print (str)
return
Arbitrary Arguments:
def my_function(*kids):
print("The youngest child is " + kids[0])
print("The 2nd youngest child is " + kids[1])
print("The 3rd youngest child is " + kids[2])
my_function(“Anil", “Babu", “Chandru")
CHAPTER 4 FUCNTIONS
Pass by reference vs value:
def changeme( mylist ):#function define
mylist.append([1,2,3,4]);
print ("Values inside the function: ", mylist)
return
mylist = [10,20,30];
changeme( mylist );#function call
print ("Values outside the function: ", mylist)
Syntax:
lambda [arg1 [,arg2,.....argn]]:expression
Example:
sum = lambda arg1, arg2: arg1 + arg2;
Syntax:
return varname;
Example:
def sum( arg1, arg2 ):#function is defined
total = arg1 + arg2
print ("Inside the function : ", total)
return total;
total = sum( 10, 20 );#function is called
print ("Outside the function : ", total)
CHAPTER 4 FUCNTIONS
Global and Local Variables: (Scope of Variables)
All variables in a program may not be accessible at all locations in that
program.
This depends on where you have declared a variable.
Example:
total = 0; # This is global variable.
# Function definition is here
def sum( arg1, arg2 ):
# Add both the parameters and return them."
total = arg1 + arg2; # Here total is local variable.
print ("Inside the function local total : ", total)
return total;
sample.add(5,5)
from...import Statement
Syntax:
from modname import name1[, name2[, ... nameN]]
dir( ) Function
import math
content = dir(math)
print content
CHAPTER 6 SEQUENCES
A sequence is a group of items with a deterministic ordering.
1. Python Strings
2. Python Lists
3. Python Tuples
4. Bytes Sequences
5. Bytes Arrays
6. range() objects
PYTHON SEQUENCE OPERATIONS
Concatenation “+”
Integer Multiplication “*”
Membership “in && not in”
Python Slice “:”
Python index()
Python count()
CHAPTER 6 SEQUENCES
List Methods:
all() Return true if all elements of the list are true (or if the list is
empty).
any() Return true if any element of the list is true. If the list is
empty, return false.
enumerate() Return an enumerate object. It contains the index and value
of all the items of list as a tuple.
len() Return the length (the number of items) in the list.
list() Convert an iterable (tuple, string, set, dictionary) to a list.
max() Return the largest item in the list.
min() Return the smallest item in the list.
sorted() Return a new sorted list (does not sort the list itself).
Example:
tup=(‘A’,’L’,’L’,’I’,’S’,’W’,’E’,’L’,’L’)
print(tup.count(‘L’))
print(tup.index(‘W’))
print(‘S’ in tup)
print(‘N’ not in tup)
CHAPTER 6 SEQUENCES
Built-in Functions with Tuple:
Function Name Description
all() Return true if all elements of the tuple are true (or if the tuple
is empty).
any() Return true if any element of the tuple is true. If the tuple is
empty, return false.
enumerate() Return an enumerate object. It contains the index and value
of all the tuple as pairs.
len() Return the length (the number of items) in the tuple.
tuple() Convert an iterable (list, string, set, dictionary) to a tuple.
max() Return the largest item in the tuple.
min() Return the smallest item in the tuple.
sorted() Take elements in the tuple and return a new sorted tuple
(does not sort the tuple itself).
sum() Return the sum of all elements in the tuple.
CHAPTER 7 PYTHON STRINGS, SETS AND DICTIONARY
Python Set
Python Strings
Python Dictionaries
CHAPTER 7 CONTINUES…
Python Set Methods:
all() Return true if all elements of the set are true (or if the set is
empty).
any() Return true if any element of the set is true. If the set is
empty, return false.
enumerate() Return an enumerate object. It contains the index and value
of all the items of set as a pair.
len() Return the length (the number of items) in the set.
max() Return the largest item in the set.
min() Return the smallest item in the set.
sorted() Return a new sorted list from elements in the set (does not
sort the set itself).
sum() Return the sum of all elements in the set.
CHAPTER 7 CONTINUES…
Python String Methods:
Methods Name Description
capitalize() It returns a copy of the string with only its first character
capitalized.
center() Returns centered in a string of length width.
count() Returns the number of occurrences of substring sub in the
range[start,end].
find() It determines if string str occurs in string, or in a substring of
string if starting index beg and ending index end are given.
replace() Returns a copy of the string in which the occurrence of old
have been replaced with new.
isalpha() Returns true if string has at least 1 character and all
characters are alphabetic and false otherwise.
isdigit() Returns true if string contains only digits and false
otherwise.
islower() Returns true if string has at least 1 cased character and all
cased characters are in lowercase and false otherwise.
CHAPTER 7 CONTINUES…
Python String Methods:
Methods Name Description
all() Return true if all keys of the dictionary are true (or if the
dictionary is empty).
any() Return true if any key of the dictionary is true. If the
dictionary is empty, return false.
len() Return the length (the number of items) in the dictionary.
sorted() Return a new sorted list of keys in the dictionary.
9 a
Opens a file for appending. The file pointer is at the end of the file if the file exists. That is,
the file is in the append mode. If the file does not exist, it creates a new file for writing.
10 ab
Opens a file for appending in binary format. The file pointer is at the end of the file if the
file exists. That is, the file is in the append mode. If the file does not exist, it creates a new
file for writing.
11 a+
Opens a file for both appending and reading. The file pointer is at the end of the file if the
file exists. The file opens in the append mode. If the file does not exist, it creates a new file
for reading and writing.
12 ab+
Opens a file for both appending and reading in binary format. The file pointer is at the end
of the file if the file exists. The file opens in the append mode. If the file does not exist, it
creates a new file for reading and writing.
CHAPTER 8 FILES I/O
EOFError: It occurs when the end of the file is reached, and yet
operations are being performed.
CHAPTER 9 EXCEPTIONS
Handling an exception:
Syntax
Here is simple syntax of try....except...else blocks −
try:
You do your operations here;
......................
except ExceptionI:
If there is ExceptionI, then execute this block.
except ExceptionII:
If there is ExceptionII, then execute this block.
......................
else:
If there is no exception then execute this block.
CHAPTER 9 EXCEPTIONS
Example: 1
try:
a = int(input("Enter a:"))
b = int(input("Enter b:"))
c = a/b
except:
Example: 2
try:
a = int(input("Enter a:"))
b = int(input("Enter b:"))
c = a/b
print("a/b = %d"%c)
# Using Exception with except statement. If we print(Exception) it will
return exception class
except Exception:
print("can't divide by zero")
print(Exception)
else:
print("Hi I am else block")
CHAPTER 9 EXCEPTIONS
Declaring Multiple Exceptions
The Python allows us to declare the multiple exceptions with the except
clause.
Declaring multiple exceptions is useful in the cases where a try block
throws multiple exceptions.
The syntax is given below:
try:
#block of code
else:
#block of code
CHAPTER 9 EXCEPTIONS
Example:3
try:
a=10/0;
except(ArithmeticError, IOError):
print("Arithmetic Exception")
else:
print("Successfully Done")
CHAPTER 9 EXCEPTIONS
The try...finally block:
Python provides the optional finally statement, which is used with the try
statement.
It is executed no matter what exception occurs and used to release the
external resource.
The finally block provides a guarantee of the execution.
The syntax to use the finally block is given below:
try:
# block of code
# this may throw an exception
finally:
# block of code
# this will always be executed
CHAPTER 9 EXCEPTIONS
Example:4
try:
fileptr = open("sample2.txt","r")
try:
fileptr.write("Hi I am good")
finally:
fileptr.close()
print("file closed")
except:
print("Error")
CHAPTER 9 EXCEPTIONS
2. Assertions - An assertion is a sanity-check that you can turn on or turn
off when you are done with your testing of the program.
Assertions are carried out by the assert statement, the newest keyword to
Python, introduced in version 1.5.
Namespaces in Python
A namespace is a collection of currently defined symbolic names along with
information about the object that each name references.
You can think of a namespace as a dictionary in which the keys are the object
names and the values are the objects themselves.
1. Built-In
2. Global
3. Enclosing
4. Local
CHAPTER 10 NAMESPACE AND SCOPE
>>> dir(__builtins__)
That namespace is local to the function and remains in existence until the function
terminates.
Functions don’t exist independently from one another only at the level of the main
program.
>>> f()
global
CHAPTER 10 NAMESPACE AND SCOPE
>>> f()
enclosing
CHAPTER 10 NAMESPACE AND SCOPE
>>> f()
local
CHAPTER 10 NAMESPACE AND SCOPE
Example: No Definition
>>> def f():
...
... def g():
... print(x)
...
... g()
...
>>> f()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 6, in f
File "<stdin>", line 4, in g
NameError: name 'x' is not defined
CHAPTER 10 NAMESPACE AND SCOPE
Variable Scope
The existence of multiple, distinct namespaces means several different instances of
a particular name can exist simultaneously while a Python program runs.
Suppose you refer to the name x in your code, and x exists in several
namespaces. How does Python know which one you mean?
The scope of a name is the region of a program in which that name has meaning.
The interpreter determines this at runtime based on where the name definition
occurs and where in the code the name is referenced.
CHAPTER 10 NAMESPACE AND SCOPE
Example:
prog_var = 'Hello'
def outer_func():
outer_var = 'x'
def inner_func():
inner_var = 'y'
print(dir(), ' Local Variable in Inner function')
inner_func()
print(dir(), 'Local variables in outer function')
outer_func()
print(dir(), 'Global variables ')
CHAPTER 10 NAMESPACE AND SCOPE
>>> type(globals())
<class 'dict'>
>>> globals()
... s = 'foo'
... print(locals())
...
Concepts of OOPs terms such as class, objects, methods etc. along with
Class
A class is a blueprint for the objects.
For example, CSC, NIIT, Infiniti, Infotech are all objects so we can define a
template (blueprint) class ComputerCentre for these objects.
The class can define the common attributes and behaviours of all the objects.
Methods
As we discussed above, an object has attributes and behaviours.
These behaviours are called methods in programming.
CHAPTER 11 OBJECTS AND CLASS
Some points on Python class:
class ClassName:
# Statement-1
.
.
.
# Statement-N
CHAPTER 11 OBJECTS AND CLASS
An object consists of :
properties of an object.
Identity: It gives a unique name to an object and enables one object to interact
Data member − A class variable or instance variable that holds data associated
with a class and its objects.
Inheritance − The transfer of the characteristics of a class to other classes that are
derived from it.
Object − A unique instance of a data structure that's defined by its class. An object
comprises both data members (class variables and instance variables) and methods.
Creating Classes
The class statement creates a new class definition. The name of the class
immediately follows the keyword class followed by a colon as follows −
class ClassName:
class_suite
def displayCount(self):
print ("Total Employee %d" % Employee.empCount)
def displayEmployee(self):
print ("Name : ", self.name, ", Salary: ", self.salary)
CHAPTER 11 OBJECTS AND CLASS
Example: Explanation
The variable empCount is a class variable whose value is shared among all
instances of a this class.
This can be accessed as Employee.empCount from inside the class or outside the
class.
The first method __init__() is a special method, which is called class constructor or
initialization method that Python calls when you create a new instance of this class.
You declare other class methods like normal functions with the exception that the
first argument to each method is self.
Python adds the self argument to the list for you; you do not need to include it
when you call the methods.
CHAPTER 11 OBJECTS AND CLASS
Creating Instance Objects
To create instances of a class, you call the class using class name and pass in
whatever arguments its __init__ method accepts.
Accessing Attributes
You access the object's attributes using the dot operator with object. Class variable
would be accessed using class name as follows −
emp1.displayEmployee()
emp2.displayEmployee()
print ("Total Employee %d" % Employee.empCount)
CHAPTER 11 OBJECTS AND CLASS
Example of Class and Objects:
In this example, we have two objects Ram and Steve that belong to the class
Human
Object attributes: name, height, weight
Object behaviour: eating() --- method
class Human:
# instance attributes
def __init__(self, name, height, weight):
self.name = name
self.height = height
self.weight = weight
# instance methods (behaviours)
def eating(self, food):
return "{} is eating {}".format(self.name, food)
print(ram.eating("Pizza"))
__bases__ − A possibly empty tuple containing the base classes, in the order of
their occurrence in the base class list.
CHAPTER 11 OBJECTS AND CLASS
Example using Built_In Class attributes:
class Employee:
'Common base class for all employees'
empCount = 0
def displayCount(self):
print ("Total Employee %d" % Employee.empCount)
def displayEmployee(self):
print ("Name : ", self.name, ", Salary: ", self.salary)
Program continues in next page…
CHAPTER 11 OBJECTS AND CLASS
Python Inheritance
Inheritance allows us to define a class that inherits all the methods and
properties from another class.
Parent class is the class being inherited from, also called base class.
Child class is the class that inherits from another class, also called
derived class.
Python Inheritance Syntax
class BaseClass:
Body of base class
class DerivedClass(BaseClass):
Body of derived class
CHAPTER 12 INHERITANCE
Any class can be a parent class, so the syntax is the same as creating any other
class:
Example
Create a class named Person, with firstname and lastname properties, and a
printname method:
class Person:
def __init__(self, fname, lname):
self.firstname = fname
self.lastname = lname
def printname(self):
print(self.firstname, self.lastname)
#Use the Person class to create an object, and then execute the printname
method:
x = Person(“Nandakumar", “Pandiyan")
x.printname()
CHAPTER 12 INHERITANCE
To create a class that inherits the functionality from another class, send the parent
class as a parameter when creating the child class:
Example
Create a class named Student, which will inherit the properties and methods from
the Person class:
class Student(Person):
pass
#Use the Student class to create an object, and then execute the printname
method:
x = Student(“Aadhish", “Nandakumar")
x.printname()
CHAPTER 12 INHERITANCE
So far we have created a child class that inherits the properties and methods from
its parent.
We want to add the __init__() function to the child class (instead of the pass
keyword).
Note: The __init__() function is called automatically every time the class is
being used to create a new object.
Example
class Student(Person):
When you add the __init__() function, the child class will no longer inherit the
parent's __init__() function.
Note: The child's __init__() function overrides the inheritance of the parent's
__init__() function.
To keep the inheritance of the parent's __init__() function, add a call to the parent's
__init__() function:
Example
class Student(Person):
Now we have successfully added the __init__() function, and kept the inheritance
of the parent class, and we are ready to add functionality in the __init__() function.
CHAPTER 12 INHERITANCE
Python also has a super() function that will make the child class inherit all the
methods and properties from its parent:
Example
class Student(Person):
super().__init__(fname, lname)
By using the super() function, you do not have to use the name of the parent
element, it will automatically inherit the methods and properties from its parent.
CHAPTER 12 INHERITANCE
Add Properties:
Example
class Student(Person):
super().__init__(fname, lname)
self.graduationyear = 2010
CHAPTER 12 INHERITANCE
In the example below, the year 2010 should be a variable, and passed into the
Student class when creating student objects. To do so, add another parameter in the
__init__() function:
Example
Add a year parameter, and pass the correct year when creating objects:
class Student(Person):
super().__init__(fname, lname)
self.graduationyear = year
Add Methods:
Example
class Student(Person):
super().__init__(fname, lname)
self.graduationyear = year
def welcome(self):
If you add a method in the child class with the same name as a function in the
parent class, the inheritance of the parent method will be overridden.
CHAPTER 13 NETWORK PROGRAMMING
At a low level, you can access the basic socket support in the underlying
operating system, which allows you to implement clients and servers for
both connection-oriented and connectionless protocols.
What is Sockets?
2 type
The type of communications between the two endpoints, typically
SOCK_STREAM for connection-oriented protocols and SOCK_DGRAM for
connectionless protocols.
3 protocol
Typically zero, this may be used to identify a variant of a protocol within a domain
and type.
4 hostname
The identifier of a network interface −
•A string, which can be a host name, a dotted-quad address, or an IPV6 address in
colon (and possibly dot) notation
•A string "<broadcast>", which specifies an INADDR_BROADCAST address.
•A zero-length string, which specifies INADDR_ANY, or
•An Integer, interpreted as a binary address in host byte order.
5 port
Each server listens for clients calling on one or more ports. A port may be a Fixnum
port number, a string containing a port number, or the name of a service.
CHAPTER 13 NETWORK PROGRAMMING
A Simple Server
# This is server.py file
import socket # Import socket module
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service
s.bind((host, port)) # Bind to the port
s.listen(5) # Now wait for client connection
while True:
c, addr = s.accept() # Establish connection with client
print ('Got connection from', addr)
c.send(b'Thank you for connecting')
c.close() # Close the connection
CHAPTER 13 NETWORK PROGRAMMING
A Simple Client
# This is client.py file
import socket # Import socket module
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service.
s.connect((host, port))
print (s.recv(1024))
s.close() # Close the socket when done
How to run?
# Following would start a server in background
$ python server.py &
# Once server is started run client as follows
$ python client.py
CHAPTER 13 NETWORK PROGRAMMING
Python Internet modules
A list of some important modules in Python Network/Internet
programming.
Protocol Common function Port No Python module
HTTP Web pages 80 httplib, urllib,
xmlrpclib
NNTP Usenet news 119 nntplib
FTP File transfers 20 ftplib, urllib
SMTP Sending email 25 smtplib
POP3 Fetching email 110 poplib
IMAP4 Fetching email 143 imaplib
Telnet Command lines 23 telnetlib
Gopher Document transfers 70 gopherlib, urllib
Protocol Common function Port No Python module
HTTP Web pages 80 httplib, urllib,
xmlrpclib
NNTP Usenet news 119 nntplib
CHAPTER 14 MULTITHREADING PROGRAMMING
Thread
An executable program.
Multiple threads within a process share the same data space with the
main thread and can therefore share information or communicate with
each other more easily than if they were separate processes.
This method call enables a fast and efficient way to create new threads
in both Linux and Windows.
The method call returns immediately and the child thread starts and calls
function with the passed list of args. When function returns, the thread
terminates.
start() − The start() method starts a thread by calling the run method.
Once you have created the new Thread subclass, you can create an instance
of it and then start a new thread by invoking the start(), which in turn calls
run() method.
CHAPTER 14 MULTITHREADING PROGRAMMING
Example 1
import threading
import time
exitFlag = 0
def print_square(num):
"""
function to print square of given num
"""
print("Square: {}".format(num * num))
Program continues in next page….
CHAPTER 14 MULTITHREADING PROGRAMMING
if __name__ == "__main__":
# creating thread
t1 = threading.Thread(target=print_square, args=(10,))
t2 = threading.Thread(target=print_cube, args=(10,))
# starting thread 1
t1.start()
# starting thread 2
t2.start()
https://www.programiz.com/python-programming
https://www.w3schools.com/python/
https://www.tutorialspoint.com/python/index.htm
https://www.python.org/about/gettingstarted/
https://www.guru99.com/python-tutorials.html
https://www.javatpoint.com/python-programs
https://stackify.com/learn-python-tutorials/
https://www.geeksforgeeks.org/python-programming-examples/
https://beginnersbook.com/2018/02/python-programs/
THANK YOU
AND