Class 12 Computer Science, Chapter 4 - Using Python Libraries. Self learning Presentation in the form of Teacher - Student conversation.
Size 20.1 MB ppt format is also available at the same site Size 5.4 MB
This presentation is all about various built in
datastructures which we have in python.
List
Dictionary
Tuple
Set
and various methods present in each data structure
These are the slides of the second part of this multi-part series, from Learn Python Den Haag meetup group. It covers List comprehensions, Dictionary comprehensions and functions.
In this chapter we will explore strings. We are going to explain how they are implemented in Java and in what way we can process text content. Additionally, we will go through different methods for manipulating a text: we will learn how to compare strings, how to search for substrings, how to extract substrings upon previously settled parameters and last but not least how to split a string by separator chars. We will demonstrate how to correctly build strings with the StringBuilder class. We will provide a short but very useful information for the most commonly used regular expressions.
Class 12 Computer Science, Chapter 4 - Using Python Libraries. Self learning Presentation in the form of Teacher - Student conversation.
Size 20.1 MB ppt format is also available at the same site Size 5.4 MB
This presentation is all about various built in
datastructures which we have in python.
List
Dictionary
Tuple
Set
and various methods present in each data structure
These are the slides of the second part of this multi-part series, from Learn Python Den Haag meetup group. It covers List comprehensions, Dictionary comprehensions and functions.
In this chapter we will explore strings. We are going to explain how they are implemented in Java and in what way we can process text content. Additionally, we will go through different methods for manipulating a text: we will learn how to compare strings, how to search for substrings, how to extract substrings upon previously settled parameters and last but not least how to split a string by separator chars. We will demonstrate how to correctly build strings with the StringBuilder class. We will provide a short but very useful information for the most commonly used regular expressions.
Learn how to use lists in Java, how to use List<T> and ArrayList<T>, how to process lists of elements.
Watch the video lesson and access the hands-on exercises here: https://softuni.org/code-lessons/java-foundations-certification-lists
Inspired by Josh Bloch's Java Puzzlers, we put together our own Python Puzzlers. This slide deck brings you a set of 10 python puzzlers, that are fun and educational. Each puzzler will show you a piece of python code. Your task if to figure out what happens when the code is run. Whether you're a python beginner or a passionate python veteran, we hope that there's something to learn for everybody.
This slide deck was first presented at shopkick. Nandan Sawant and Ryan Rueth are engineers at shopkick. Keeping the audience in mind, most of the puzzlers are based on python 2.x.
Learn how to use arrays in Java, how to enter array, how to traverse an array, how to print array and more array operations.
Watch the video lesson and access the hands-on exercises here: https://softuni.org/code-lessons/java-foundations-certification-arrays
Python is an interpreted, high-level, and general-purpose programming language.
It is an easy to learn general-purpose programing language.
It is a platform-independent programing language, which means it can be used on any machine and in any operating system.
It has a simple syntax
Python is a case sensitive language.
It is an interrupted language.
It is free to use and even free for commercial products.
Introduction to the basics of Python programming (part 3)Pedro Rodrigues
This is the 3rd part of a multi-part series that teaches the basics of Python programming. It covers list and dict comprehensions, functions, modules and packages.
In this chapter we will review how to work with text files in C#. We will explain what a stream is, what its purpose is, and how to use it. We will explain what a text file is and how can you read and write data to a text file and how to deal with different character encodings. We will demonstrate and explain the good practices for exception handling when working with files. All of this will be demonstrated with many examples in this chapter
Java Foundations: Data Types and Type ConversionSvetlin Nakov
Learn how to use data types and variables in Java, how variables are stored in the memory and how to convert from one data type to another.
Watch the video lesson and access the hands-on exercises here: https://softuni.org/code-lessons/java-foundations-certification-data-types-and-variables
All data values in Python are encapsulated in relevant object classes. Everything in Python is an object and every object has an identity, a type, and a value. Like another object-oriented language such as Java or C++, there are several data types which are built into Python. Extension modules which are written in C, Java, or other languages can define additional types.
To determine a variable's type in Python you can use the type() function. The value of some objects can be changed. Objects whose value can be changed are called mutable and objects whose value is unchangeable (once they are created) are called immutable.
The presentation from SPb Python Interest Group community meetup.
The presentation tells about the dictionaries in Python, reviews the implementation of dictionary in CPython 2.x, dictionary in CPython 3.x, and also recent changes in CPython 3.6. In addition to CPython the dictionaries in alternative Python implementations such as PyPy, IronPython and Jython are reviewed.
Learn how to use lists in Java, how to use List<T> and ArrayList<T>, how to process lists of elements.
Watch the video lesson and access the hands-on exercises here: https://softuni.org/code-lessons/java-foundations-certification-lists
Inspired by Josh Bloch's Java Puzzlers, we put together our own Python Puzzlers. This slide deck brings you a set of 10 python puzzlers, that are fun and educational. Each puzzler will show you a piece of python code. Your task if to figure out what happens when the code is run. Whether you're a python beginner or a passionate python veteran, we hope that there's something to learn for everybody.
This slide deck was first presented at shopkick. Nandan Sawant and Ryan Rueth are engineers at shopkick. Keeping the audience in mind, most of the puzzlers are based on python 2.x.
Learn how to use arrays in Java, how to enter array, how to traverse an array, how to print array and more array operations.
Watch the video lesson and access the hands-on exercises here: https://softuni.org/code-lessons/java-foundations-certification-arrays
Python is an interpreted, high-level, and general-purpose programming language.
It is an easy to learn general-purpose programing language.
It is a platform-independent programing language, which means it can be used on any machine and in any operating system.
It has a simple syntax
Python is a case sensitive language.
It is an interrupted language.
It is free to use and even free for commercial products.
Introduction to the basics of Python programming (part 3)Pedro Rodrigues
This is the 3rd part of a multi-part series that teaches the basics of Python programming. It covers list and dict comprehensions, functions, modules and packages.
In this chapter we will review how to work with text files in C#. We will explain what a stream is, what its purpose is, and how to use it. We will explain what a text file is and how can you read and write data to a text file and how to deal with different character encodings. We will demonstrate and explain the good practices for exception handling when working with files. All of this will be demonstrated with many examples in this chapter
Java Foundations: Data Types and Type ConversionSvetlin Nakov
Learn how to use data types and variables in Java, how variables are stored in the memory and how to convert from one data type to another.
Watch the video lesson and access the hands-on exercises here: https://softuni.org/code-lessons/java-foundations-certification-data-types-and-variables
All data values in Python are encapsulated in relevant object classes. Everything in Python is an object and every object has an identity, a type, and a value. Like another object-oriented language such as Java or C++, there are several data types which are built into Python. Extension modules which are written in C, Java, or other languages can define additional types.
To determine a variable's type in Python you can use the type() function. The value of some objects can be changed. Objects whose value can be changed are called mutable and objects whose value is unchangeable (once they are created) are called immutable.
The presentation from SPb Python Interest Group community meetup.
The presentation tells about the dictionaries in Python, reviews the implementation of dictionary in CPython 2.x, dictionary in CPython 3.x, and also recent changes in CPython 3.6. In addition to CPython the dictionaries in alternative Python implementations such as PyPy, IronPython and Jython are reviewed.
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkreddyprasad reddyvari
3 days Hands on workshop on MATLAB/SIMULINK for Engineering Applications:
this workshop aims to make students to aware of MATLAB to do own projects in engineering life with best available technology E-Simulink Softwares and tools.
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...DRVaibhavmeshram1
Python
Language
is uesd in engineeringStory adapted from Stephen Covey (2004) “The Seven Habits of Highly Effective People” Simon & Schuster).
“Management is doing things right, leadership is doing the right things”
(Warren Bennis and Peter Drucker)
Story adapted from Stephen Covey (2004) “The Seven Habits of Highly Effective People” Simon & Schuster).
“Management is doing things right, leadership is doing the right things”
(Warren Bennis and Peter Drucker)
Story adapted from Stephen Covey (2004) “The Seven Habits of Highly Effective People” Simon & Schuster).
“Management is doing things right, leadership is doing the right things”
(Warren Bennis and Peter Drucker)
The Sponsor:
Champion and advocates for the change at their level in the organization.
A Sponsor is the person who won’t let the change initiative die from lack of attention, and is willing to use their political capital to make the change happen
The Role model:
Behaviors and attitudes demonstrated by them are looked upon by everyone else. . Hence, they must be willing to go first.
Employees watch leaders for consistency between words and actions to see if they should believe the change is really going to happen.
The decision maker:
Leaders usually control resources such as people, budgets, and equipment, and thus have the authority to make decisions (as per their span of control) that affect the initiative.
During change, leaders must leverage their decision-making authority and choose the options that will support the initiative.
The Decision-Maker is decisive and sets priorities that support change.
The Sponsor:
Champion and advocates for the change at their level in the organization.
A Sponsor is the person who won’t let the change initiative die from lack of attention, and is willing to use their political capital to make the change happen
The Role model:
Behaviors and attitudes demonstrated by them are looked upon by everyone else. . Hence, they must be willing to go first.
Employees watch leaders for consistency between words and actions to see if they should believe the change is really going to happen.
The decision maker:
Leaders usually control resources such as people, budgets, and equipment, and thus have the authority to make decisions (as per their span of control) that affect the initiative.
During change, leaders must leverage their decision-making authority and choose the options that will support the initiative.
The Decision-Maker is decisive and sets priorities that support change.
The Sponsor:
Champion and advocates for the change at their level in the organization.
A Sponsor is the person who won’t let the change initiative die from lack of attention, and is willing to use their political capital to make the change happen
The Role model:
Behaviors and attitudes demonstrated by them are looked upon by everyone else. . Hence, they must be willing to go first.
Employees watch leaders for consistency between words and actions to see if they s
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
Biological screening of herbal drugs: Introduction and Need for
Phyto-Pharmacological Screening, New Strategies for evaluating
Natural Products, In vitro evaluation techniques for Antioxidants, Antimicrobial and Anticancer drugs. In vivo evaluation techniques
for Anti-inflammatory, Antiulcer, Anticancer, Wound healing, Antidiabetic, Hepatoprotective, Cardio protective, Diuretics and
Antifertility, Toxicity studies as per OECD guidelines
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
6. Modules, packages, and libraries are
all different ways to reuse a code.
Modules
Packages
libraries
7. A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended.
A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended.
A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended.
Look at the board. There are
some functions, classes, constant
and some other statements.
Absolutely this is a module.
Module is a collection
of functions, classes,
constants and other
statements.
8. Write the code on the board
in a file and save it with a
name with .py suffix.
It becomes a module.
9. Yes2. I want to write
some more module
files.
Can you try your
own modules ?
Good. That is Package.
10. A group of modules saved in a
folder is called package.
I want a package contains
my own modules.
Collection of modules
saved in a folder, are
called package.
11. Library is a collection of packages.
Suppose we write more packages about
anything. It will become a library. In
general, the terms package and library
have the same meaning.
13. The Python Standard Library contains
built-in data, functions, and many modules.
All are part of the Python installation.
Basic Contents of Standard Library.
15. print ( "10 + 20 = ", 10 + 20 )
print ( "Cube of 2 is ", 2 ** 3 )
import math
print ("Square root of 25 is ", math.sqrt(25) )
print ("Cube of 2 is ", math.pow(2,3) )
print(), input(),
10 + 20 are basic operation.
No need to import anything.
sqrt () and pow () are defined in
Math module. So need to
import math modules.
We use the
Statement to import other
modules into our programs.
16. hex ( Integer Argument )
oct ( Integer Argument )
int ( string / float Argument )
round ( )
Examples of Built-in Function.
Accept an integer in any
system and returns its
octal equivalent as string.
>>> oct ( 10 )
OUTPUT : ‘0o12’
Accept an integer in any system and returns
its Hexadecimal equivalent as string.>>> hex ( 10 )
OUTPUT : ‘0xa’
The int() function returns
integer value of given value.
The given float number is rounded
to specified number of
decimal places.
>>> int ( 3.14 )
OUTPUT : 3
>>> round ( 3.65,0 )
OUTPUT : 4.0
In oct, 1, 2, 3, 4,
5, 6, 7, What
next ?
17. oct(),hex() and bin() Functions.
Don't worry. you just count 1 to 20 using
for a in range(1,21) And use hex() and oct()
functions. The computer will do everything for you.
Octal system has only 8
digits. They are 0 to 7. after 7,
write 10 for 8, 11 for 9, 12 for
10 etc.
Hexadecimal system has 16
digits. They are 0 to 9 and 'a'
for 10, 'b' for 11... 'f' for 15.
After 15, write 10 for 16, 11 for
18. print ("Numbering System Table")
print("column 1: Decimal System, col2 : Octal, col3: Hex, col4: Binary")
for a in range(1,25):
print(a, oct(a), hex(a), bin(a) )
Numbering System Table
column 1 :Decimal System, col2 : Octal,
col3: Hex, col4: Binary
1 0o1 0x1 0b1
2 0o2 0x2 0b10
3 0o3 0x3 0b11
4 0o4 0x4 0b100
5 0o5 0x5 0b101
6 0o6 0x6 0b110
16 0o20 0x10 0b10000
17 0o21 0x11 0b10001
18 0o22 0x12 0b10010
19 0o23 0x13 0b10011
20 0o24 0x14 0b10100
21 0o25 0x15 0b10101
22 0o26 0x16 0b10110
23 0o27 0x17 0b10111
24 0o30 0x18 0b11000
oct() convert given value to octal system.
hex() convert given value to Hexadecimal system.
bin() convert given value to Binary system.
OUTPUT
CODE
19. int ( float/string Argument )
round (float , No of Decimals)
int () and round () Function.
The int() function returns integer value
(No decimal places) of given value. The given
value may be an integer, float or a string like “123”
The given float number is rounded to specified
number of decimal places. If the ignoring number is
above .5 ( >=.5) then the digit before it will be added by 1.
>>> int ( 3.14 )
OUTPUT : 3
>>> int (10/3)
OUTPUT : 3
>>> int( “123” )
OUTPUT : 123
>>> round ( 3.65 , 0 )
OUTPUT : 4.0
20. Join the words “lion”, “tiger” and
“leopard” together.
Replace all "a" in “Mavelikkara” with "A".
Split the line 'India is my motherland'
into separate words.
“anil” + “kumar” = “anil kumar”,
“anil” * 3 = “anilanilanil”. These are
the basic operations of a string.
21. string.split() function splits a string into a list.
>>> x = "All knowledge is within us.“
>>>
We get the list ['All', 'knowledge', 'is', 'within', 'us.']
Wrong use Right use
Prefix
22. >>> x = "Mathew,Krishna,David,Ram"
>>> x.split( “,” )
We get the list ['Mathew', 'Krishna', 'David', 'Ram']
Cut when
you see “n“.
>>> x = "MathewnKrishnanDavidnRam"
>>> x.split( “n” )
We get the list ['Mathew', 'Krishna', 'David', 'Ram']
>>> x = "MAVELIKARA"
>>> x.split("A")
We get the list ['M', 'VELIK', 'R', '']
"MAVELIKARA" Is it
Fun?
23. string.join() joins a set of string into a single string.
Delimit string.join ( collection of string )
“,”. join ( [‘Item1’, ‘Item2’, ‘Item3’] )
‘Item1’
‘Item1,Item2’
1
2
3
Item1,Item2,Item3End
>>> a = ['Matthew', 'Krishna', 'David','Ram']
>>> ",".join(a) OUTPUT : 'Matthew,Krishna,David,Ram'
24. Do it in Python.
>>> a = ['Trissur','Ernakulam','Kottayam', 'Mavelikara' ]
>>>> "->".join(a)
'Trissur->Ernakulam->Kottayam->Mavelikara'
25. Can you change
zebra to cobra?
replace () Function. replace () Function.
function replaces a phrase with
another phrase.
string.replace(what, with, count )
What to replace?
Replace with what?
How many replacement is
needed.(optional)
>>> ‘zebra’.replace(‘ze’,’co’)
cobra zebra becomes cobra
>>> ‘cobra’.replace(‘co’,’ze’)
zebra cobra becomes zebra
26. Modules such as math, cmath, random, statistics, urllib are
not an integral part of Python Interpreter. But they are
part of the Python installation. If we need them,
import them into our program and use them.
We use "Import” statement to import
Other modules into our programs.
It has many forms. We will learn in detail later.
Syntax is import < module Name >
E.g. import math
import random
27. Python does a series of actions when you import module,
They are
The code of importing modules is interprets
and executed.
Defined functions and variables in the
module are now available.
A new namespace is setup for importing modules.
28. A namespace is a dictionary that contains the names and definitions
of defined functions and variables. Names are like keys and
definitions are values. It will avoid ambiguity between 2 names.
I teach 2 Abhijit. one is in class XI-B and
other is in class XII-A. How can I write
theirname without ambiguity.
class XI-B.Abhijit class XII-A.Abhijit
29. Are not Ashwin in 12.B?
Your Reg. No 675323.
No Sir, Check
the list of 12.A
30. Who is കുഴിക്കാലായിൽ
അബ്രഹാാം(K M Abraham)
He is a member of
കുഴിക്കാലായിൽ
family.
An object (variable, functions
etc.) defined in a namespace is
associated with that
namespace. This way, the
same identifier can be defined
in multiple namespaces.
>>> math.
Output : 5
>>> math.pi
Output :3.141592653589793
Google K.M. Abraham.
Name of
Namespace
Object in that
Namespace
31. math
math and cmath modules covers many mathematical
functions.
and .
More than 45 functions and 5 constants are defined in it.
The use of these functions can be understood by their
name itself.
2. Place (Namespace) before function name.
1. import math
X = sqrt(25)
Name of
Namespace
Object in that
Namespace
33. >>> help(math)
Traceback (most recent call last): File "<pyshell#1>", line 1, in <module>
help(math)
NameError: name 'math' is not defined
>>> import math
>>> help (math)
Help on built-in module math:
NAME
math
DESCRIPTION
This module provides access to the mathematical functions
defined by the C standard.
34. FUNCTIONS.import math
The value without –ve / +ve symbol is called
absolute value. Both functions give absolute value, while fabs () always give a float
value, but abs () gives either float or int depending on the argument.
>>> abs(-5.5) >>> abs(5)
Output : 5.5 5
>>> math.fabs(5) >>> math.fabs(5.5)
Output : 5.0 5.5
Returns factorial value
of given Integer. Error will occur if you enter a -ve or a float value.
>>> >>> math.factorial(-5)
Output : 120 >>> math.factorial(5.5)
Wrong useRight use
Abs() is built-in
function.
35. fmod function returns the
remainder when x is divided by y. Both x and y must be a
number otherwise error will occur.
What is the remainder when
10.32 is divided by 3? >>> import math
>>> math.fmod(10.32,3)
1.32
What is the remainder when
11.5 is dividedby 2.5?
𝟏𝟎.𝟑𝟐
𝟑
= 3 × 3 = 9
𝑟𝑒𝑚𝑎𝑖𝑛𝑖𝑛𝑔 1.32
>>> import math
>>> math.fmod(11.5,2.5)
1.5
36. modf () separates fractional
and integer parts from a floating point number. The result
will be a tuple. using multiple assignment, you can assign
these 2 values in 2 variables.
Can you separate the fraction and
the integer parts of pi value?
>>> import math
>>> math.modf(math.pi)
(0.14159265358979312, 3.0)
>>> a , b = math.modf(math.pi)
a= 0.14159265358979312, b = 3
Fractional part Integer part
Tuple data type
37. Statistics module provides 23 statistical functions. Some of
them are discussed here.
Before using them. And call with “statistics.” prefix.
mean() calculate
Arithmetic mean (average) of data.
>>> import statistics
>>> statistics.mean( [1,2,3,4,5] )
Output : 3
>>> statistics.mean( [1,2,3,4,5,6] )
Output : 3.5
Sum of Values
Count of Values
Mean is
calculated as
38. The middle value of a sorted list of numbers is called
median. If the number of values is odd, it will return the
middle value. If the number is even, the median is the
midpoint of middle two values.
>>> import statistics
>>> a = [10,20,25,30,40]
>>> statistics.median(a)
Output : 25
a = [10, 20, 25,30, 40, 50]
>>> statistics.median(a)
Output : 27.5
Here ,number of values is 5, an odd
No, So returns the middle value
Here ,number of values is 6, an even
No, So returns the average of
middle two values.
If the number of elements is
an oddnumber thenlook
up else looks down.
39. It must be a unique items, multiple items cannot be
considered as modes. Eg. MODE of [1,2,3,2,1,2] is 2 because
‘2’ occures 3 times while MODE of [1,2,3,2,1,2,1] causes
ERROR because values 1 and 2 are repeated 3 times each.
Output : 2
>>> statistics.mode(“MAVELIKARA")
Output : ‘A'
Modeof "HIPPOPOTAMUS“ is P.
No mode for KANGAROO
40. import random FUNCTIONS.
Have you used an OTP number? Sure it shall be a
random number. It has many uses in science, statistics,
cryptography, gaming, gambling and other fields.
When you throw a dice, it will generate a
randomnumber between 1-6.
41. If you need a 3 digit otp number, pick a
random number between 100 and 999.
42.
43. The webbrowser module
is used to display web pages
through Python program. Import this module and call
webbrowser.open(URL)
import webbrowser
url = "https://www.facebook.com/"
webbrowser.open(url)
webbrowser.open("https://mail.google.com/")
webbrowser.open(“https://www.youtube.com/”)
opens mail
opens youtube
44. >>> import webbrowser
>>> webbrowser.open("https://www.slideshare.net/venugopalavarmaraja/")
.
Give any address (URL)here.
OUTPUT OF 2 LINE CODE
45. urllib is a package for working with URLs. It
contains several modules. Most important one is
'request'. So import urllib.request when working
with URLs. Some of them mentioning below..
Urllib.request.urlopen()
Open a website denoted by URL for reading. It will return
a file like object called QUrl. It is used for calling following
functions.
QUrl.read()
returns html or source code of the given url opened via
Urlopen().
QUrl.getcode()
Returns the http status code like 1xx,2xx ... 5xx. 2xx(200)
denotes success and others have their meaning.
QUrl.headers () Stores metadata about the opened url
QUrl.info () Returns some information as stored by headers.
QUrl.geturl ()
Returns the url string.
46. import urllib.request
import webbrowser
u = "https://www.slideshare.net/venugopalavarmaraja/"
weburl = urllib.request.urlopen(u)
html = weburl.read()
code = weburl.getcode()
url = weburl.geturl()
hd = weburl.headers
inf = weburl.info()
print("The URL is ", url)
print("HTTP status code = ", code )
print("Header returned ", hd )
print("The info() returned ", inf )
print("Now opening the url",url )
webbrowser.open_new(url)
Creating QUrl object(HTTP Request
Object)
Calling Functions with QUrl Object
Printing Data
Opening Website
47. So far we have learned What are modules,
packages, and libraries? And familiarized
with Standard Library. Libraries like Numpy,
Scipy, Tkinter, Matplotlib are not part of
Python Standard Libraries. So they
want to download and install. We
do It when we study 8th chapter.
Now we are going to learn
48. A module is a Python
file that contains a
collection of
functions, classes,
constants, and other
statements.
49. This is the file I wrote and saved.
File name is MYMOD.py.
What to do next.
Creating Module
50. I opened another program file
and imported MYMOD (.py).
The functions written in the
module are working well.
Example
51. Python does a series of actions when you import module,
They are
The code of importing modules is interprets
and executed.
Module functions and variables are available
now, but use module name as their prefix.
52. is a dictionary that contains the names
and definitions of defined functions and variables. Names
are like keys and definitions are values. It will avoid
ambiguity between 2 names.
I teach 2 Abhijit. one is in class XI-B and other
is in class XII-A. Howcan I write their name
without ambiguity.
class XI-B.Abhijit class XII-A.Abhijit
53.
54. The CONVERSION.pymodule contains
2 functions. They convert, lengthin feet
and inches to meters and centimeters
and vice versa
Import module
The screenshot on the left
shows the module we
created.
The screenshot below shows
how to import and use that
module.
Example 2
55. Example 3
Now creating another module
named MY_MATH.py. It contains 2
functions, fact(x) and add_up_to(x).
Import into a
new program.
56. Structure of a Module
DocString (Documentation String)
Functions
Constants/Variables
Classes
Objects
Other Statements
57. def fibi(a, b, n) :
print ("Fibonacci Series is ", end="")
for x in range(n):
print (a+b, end=", ")
a, b = b, a+b
58. def fibo(a, b, n) :
'''fibi () takes 3 arguments and generate Fibonacci series
‘a’ and ‘b’ are previous 2 elements. N is the number of
elements we want.'''
print (" Fibonacci Series is ", end="")
for x in range(n):
print (a+b, end=", ")
a, b = b, a+b
All
59. Calling help of fibo function.
The documentation string is shown.
Is it interesting? Details about the
author, version and license can be
given in the 'Dockstring'.
60. Write this code in a
Python file and save.
Goto Python Shell and call help()
61. >>> import MYMOD
>>> help(MYMOD)
Help on module MYMOD:
NAME
MYMOD
DESCRIPTION
This Module contains 4 functions.
1. add(a,b) -> Receives 2 Nos and return a + b.
2. sub(a,b) -> Receives 2 Nos and return a - b.
3. add(a,b) -> Receives 2 Nos and return a + b.
4. sub(a,b) -> Receives 2 Nos and return a - b.
FUNCTIONS
add(a, b)
add(a,b) in MYMOD module accepts 2 Nos and return a + b
div(a, b)
div(a,b) in MYMOD module accepts 2 Nos and return "a / b
mul(a, b)
mul(a,b) in MYMOD module accepts 2 Nos and return "a * b
sub(a, b)
sub(a,b) in MYMOD module accepts 2 Nos and return a - b
FILE
c:usersaug 19...programspythonpython37-32mymod.py
Calling help()
Help () function gives
documentation about functions,
classes, modules.
62. ‘’’ This module contains each function (), class, and data. ‘’’
months = ["Jan","Feb","Mar","Apr","May","Jun",
"Jul","Aug","Sep","Oct","Nov","Dec"]
class Student :
''' Just an example of Python class'''
pass
def String_Date (d, m, y) :
''' Receives d, m, y as integers and return String Form '''
if d==1 or d==21 or d==31 :
…………
return words + months[m-1] + ", " + str(y)
Documentation Sting of Class.
Function’s Documentation Sting.
63. Impot Module &Calling help
Documentation string of Function.
Name of Module
Documentation Sting of Module.
Classes defined in the Module.
Documentation Sting of Class.
Functions defined in the Module.
Data / Constatnts / Variable / Objects
Path of Module File
64.
65.
66. The package is a way to organize
modules and other resources in a neat
and tidy manner.
Module_01.py
Module_02.py
__init__.py
Package
Import modules
from them and
use as you need.
76. "Underscore underscore init
underscore underscore dot py"
__init__.py
How is it
pronounced? Double
Underscore
”Dunder” means Double Underscore.
two leading and two trailing underscores
77. __init__.py file marks folders
(directories) as Python package.
This will execute automatically
when the package is imported.
The __init__.py file initialize the
Package as its name implies.
Etc..
84. Python does a series of actions when you import package,
Python runs the initialization file __init__.py.
The modules in the package will be imported.
Defined functions of module are now available.
Creates unique namespace for each module within
the namespace of the package.
85. We have already learned about “ import ” statement at the
beginning of this chapter. With this statement, the module can be
imported as whole, but only the selected objects within the module
can't be imported.
The entire Math module
can be imported.
‘Pi' is an object
defined in the math module. Partial
import is not possible with the "Import"
statement.
86. But it is not a
standardstyle.
Multiple Modules can be imported with one import
statement.
import my_package.MYMOD,my_package.MY_MATH
87. from module import component is another way
for importing modules or packages. Selected
components can be imported using this statement,
but it is not possible with the import statement.
pi (pi = 3.1415) is a constant defined in math
module. You can’t import partial components.
Output : 3.14…
Only the required objects are imported. These are imported into the
local namespace so no "namespace dot" notation is required.
88. Only the required objects are imported. These are imported into the
local namespace so no "namespace dot" notation is required.
It is not
possible with
“import”
Statement.
required objects are imported
89. Python internally does a series of actions, when we use
The code of importing modules is interprets
and executed.
Only the imported(selected) functions
and objects are available.
Does not setup a namespace for the importing
modules.
90. .
And use this nickname(alias) instead of real name.
The clause is used to
rename importing objects.
urllib! How I
pronounce it.
Don't worry. Rename it
as ulib while
importing it.
91. The clause is used to rename
importing objects.
python will
support unicode
malayalam.
92. The file name will not change, but will
get a nickname. Look at the red square.
93. The wild card(character) is a
letter (asterisk *) used in the
sense of “all functions and
objects”.
The whole math module is imported into a
new namespace. So objects are safe and
no chance for redefining objects.
All objects in the math module will be
imported into the local namespace (local
scope). So there is a chance to redefine
many of the imported items.
94. The base of natural logarithm "e" (Euler's No) is defined in
math. There is a chance to redefine its value by accident.
95. The "Import" statement loads a module into its
own namespace, so you must enter the module
name and dot before their components.
The "from… import" statement loads the module
components into the current namespace so you
can use it without mentioning the module name.
98. Previously created package “my_package” contains
3 modules. MYMOD, MY_MATH & CONVERSION
How Import Works
Create namespace for the package and
create other 3 namespaces under it for each
modules (MYMOD, MY_MATH & CONVERSION).
Each objects goes to corresponding
module’s namespaces and were safe at
there. created Inside it and the objects of the
module were kept in them. Therefore these
namespaces should be given before the
object names.
99. How from … import Works
Exclude the namespace for my_package and create
namespace only for other 3 modules. Therefore statements
can be minimized when using module objects (components).
Output : 3
100.
101. This initiative will make sense if you
find this presentation useful.
If you find any mistakes please
comment.
Namasthe