SlideShare a Scribd company logo
Learning to Program
(…and a bit about ‘Life’)
2
What is a Computer Program?
© 2014 All Rights Reserved Confidential
A program is a sequence of instructions to perform a computational task. Essentially, any
computer program (however complex it may get), almost always is a combination of
below basic instructions:
 Input
 Output
 Mathematical Operation
 Conditional execution
 Repetition
Programming languages are formal languages that have been designed to express
computations.
3
Python
© 2015 All Rights Reserved Confidential
Python is an easy to learn powerful programming language. Some features of
python are:
• Simple
• Interpreted
• Free and Open Source
• High Level
• Portable
• Object Oriented
• Extensible
4
Interpreter vs Complier
© 2015 All Rights Reserved Confidential
• Programs written in high-level languages have to be converted into low-level language
for the computer to understand them.
• 2 kinds of program that convert high level source code to low level are: Interpreter and
Compiler
• An interpreter translates the source code line by line.
• A compiler reads the entire program and translates it completely before the program
runs. The source code is compiled into an object code which is then executed. Once a
program is complied, it can be executed many times without the need of compilation.
Source Code Interpreter Output
Source Code Compiler OutputObject Code Executor
5
Basics of Python
© 2014 All Rights Reserved Confidential
Comments: These are the descriptive text that is put in the program so that the person who is
reading it, can understand what a particular statement or a block of statements is doing. ‘#’
symbol is used to mark comments e.g
Print(“My name is Jack) # Using print() function to print name
Comments are not compiled. The compiler just ignores everything which is written after #
Numbers: Numbers are of 2 types – integers and floats. 2 is an integer but 2.34 is a floating
point number
Strings: A string is a sequence of characters. Strings are specified either using single-quotes or
double quotes.
Variables: A variable is a name that refers to a value. E.g n = 17 i.e The value 17 is assigned to
a variable named “n”. In python, variables names begin with a letter and can not contain special
characters. Also keywords can not be used as variable names. To know the type of variables,
use the function type()
6
Basics of Python..(Contd)
© 2014 All Rights Reserved Confidential
Operators: Operators are special symbols that represent computations like addition or
subtraction
+ addition
- Subtraction
* Multiplication
/ Division
** Power
// Integer Division
% Mod Operation
Expression: An expression is a combination of values, variables and operators.
7
Its refers to the methodology of programming where programs are made of object
definitions and function definitions and most of the computation is expressed in terms
of operations on objects. Each object definition corresponds to some object or concept
in real world and the functions that operate on that object correspond to the ways
real-world object interacts.
• Organizing your program to combine data and functionality
• Class creates a new type where objects are instances of the class.
• Class is like a blueprint or a template
• Variables that belong to an object or class are referred to as fields.
• Functions that belong to a class are called Methods
• Fields and Methods are known as attributes of a class.
• Fields are of two types - they can belong to each instance/object of the class or they
can belong to the class itself. They are called instance variables and class variables
respectively
Object Oriented Programming
© 2014 All Rights Reserved Confidential
8
Functions
© 2014 All Rights Reserved Confidential
• A function is a named sequence of statements that performs a computation.
• A module is a file that contains a collection of related functions.
• Packages are just folders to hierarchically organize modules.
• Each package contains a bunch of Python scripts. Each script is a module. Examples of
packages are Numpy, sckit-learn, pandas etc
9
Control Flow - If
© 2014 All Rights Reserved Confidential
3 control flow statements in Python – If, while and for
If statement is used to check a condition:
Cp = int(input(“Enter the cost price: ”))
Sp = int(input(“Enter the selling price: ”))
If(sp>cp):
print(“Congratulations! You have made a profit”)
Elif(sp<cp):
print(“Sorry! You are in loss”)
Else:
print(“No profit. No Loss”)
10
Control Flow - While
© 2014 All Rights Reserved Confidential
While statement is used to repeatedly execute a block of statements as long as a condition is
true.
# Read a number. Print the square of all numbers from 1 upto N
n= int(input("Enter a number: "))
# Initial Condition
i = 1
while(i<=n):
print(i*i)
i = i+1
11
Control Flow – For Loop
© 2014 All Rights Reserved Confidential
For statement is also used to repeatedly execute a block of statements as long as a condition is
true.
# Read a number. Print the square of all numbers from 1 upto N
n= int(input("Enter a number: "))
# Initial Condition
For I in range(1, N+1):
print(i*i)
12
Data Structures - Lists
© 2014 All Rights Reserved Confidential
Lists : A list is a data structure that holds an ordered collection of items i.e. you can
store a sequence of items in a list. Once you have created a list, you can add, remove
or search for items in the list. Since we can add and remove items, we say that
a list is a mutable data type i.e. this type can be altered.
shoplist = ['apple', 'mango', 'carrot', 'banana']
print('I have', len(shoplist), 'items to purchase.')
print('These items are:', end=' ')
for item in shoplist:
print(item, end=' ')
print('nI also have to buy rice.')
shoplist.append('rice')
print('My shopping list is now', shoplist)
print('I will sort my list now')
shoplist.sort()
print('Sorted shopping list is', shoplist)
13
Data Structures - Lists
© 2014 All Rights Reserved Confidential
print('The first item I will buy is', shoplist[0])
olditem = shoplist[0]
del shoplist[0]
print('I bought the', olditem)
print('My shopping list is now', shoplist)
# To print unique elements of a list
Mylist=list(set(mylist))
# To convert all elements of a list into numbers:
mylist=[int(x) for x in mylist]
# List Indexing:
fruits = [‘Orange’, ‘Banana’, ‘Apple’, ‘Pear’]
fruits[1] gives second element
fruits[-1] gives last element
14
Data Structures - Lists
© 2014 All Rights Reserved Confidential
# List Slicing:
To select multiple elements from a list :
Mylist[start:end]
fruits = [‘Orange’, ‘Banana’, ‘Apple’, ‘Pear’]
fruits[1:3] gives [‘Banana’, ‘Apple’]. The elements are returned with index
“start” upto index “end-1”
Fruits[1:] gives [‘Banana’, ‘Apple’, ‘Pear’]
Fruits[:3] gives [‘Orange’, ‘Banana’, ‘Apple’]
# Print last 3 elements:
Fruits[-3:]
15
Data Structures – Nested Lists
© 2014 All Rights Reserved Confidential
A list can contain other lists
>>> x = [["a", "b", "c"],
["d", "e", "f"],
["g", "h", "i"]]
X[1] results ["d", "e", "f"]
X[1][2] results “f”
16
Data Structures - Dictionary
© 2014 All Rights Reserved Confidential
A dictionary is like an address-book where you can find the address or contact
details of a person by knowing only his/her name i.e. we associate keys (name)
with values (details). Note that the key must be unique just like you cannot
find out the correct information if you have two persons with the exact same
name.
Note that you can use only immutable objects (like strings) for the keys of a
dictionary but you can use either immutable or mutable objects for the values of
the dictionary. This basically translates to say that you should use only simple
objects for keys.
17
Data Structures - Dictionary
© 2014 All Rights Reserved Confidential
ab = { ‘Gaurav' : ‘gaurav@itbodhi.com',
'Larry' : 'larry@wall.org',
'Matsumoto' : 'matz@ruby-lang.org',
'Spammer' : 'spammer@hotmail.com'
}
print(“Gaurav's address is", ab[‘Gaurav'])
# Deleting a key-value pair
del ab['Spammer']
print('nThere are {0} contacts in the address-bookn'.format(len(ab)))
for name, address in ab.items():
print('Contact {0} at {1}'.format(name, address))
# Adding a key-value pair
ab['Guido'] = 'guido@python.org'
if 'Guido' in ab:
print("nGuido's address is", ab['Guido'])

More Related Content

What's hot

Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
K Durga Prasad
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
Mohd Sajjad
 
Programming in C Session 1
Programming in C Session 1Programming in C Session 1
Programming in C Session 1
Prerna Sharma
 
C presentation
C presentationC presentation
Python Session - 3
Python Session - 3Python Session - 3
Python Session - 3
AnirudhaGaikwad4
 
Ap Power Point Chpt2
Ap Power Point Chpt2Ap Power Point Chpt2
Ap Power Point Chpt2dplunkett
 
Unit v
Unit vUnit v
Python Basics by Akanksha Bali
Python Basics by Akanksha BaliPython Basics by Akanksha Bali
Python Basics by Akanksha Bali
Akanksha Bali
 
Python Data-Types
Python Data-TypesPython Data-Types
Python Data-Types
Akhil Kaushik
 
Values and Data types in python
Values and Data types in pythonValues and Data types in python
Values and Data types in python
Jothi Thilaga P
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
Prerna Sharma
 
11 Unit 1 Chapter 02 Python Fundamentals
11  Unit 1 Chapter 02 Python Fundamentals11  Unit 1 Chapter 02 Python Fundamentals
11 Unit 1 Chapter 02 Python Fundamentals
Praveen M Jigajinni
 
Ap Power Point Chpt3
Ap Power Point Chpt3Ap Power Point Chpt3
Ap Power Point Chpt3dplunkett
 
Introduction to Python programming Language
Introduction to Python programming LanguageIntroduction to Python programming Language
Introduction to Python programming Language
MansiSuthar3
 
Cpu-fundamental of C
Cpu-fundamental of CCpu-fundamental of C
Cpu-fundamental of C
Suchit Patel
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and comments
Nilimesh Halder
 
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Ranel Padon
 
358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3
sumitbardhan
 

What's hot (18)

Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
 
Programming in C Session 1
Programming in C Session 1Programming in C Session 1
Programming in C Session 1
 
C presentation
C presentationC presentation
C presentation
 
Python Session - 3
Python Session - 3Python Session - 3
Python Session - 3
 
Ap Power Point Chpt2
Ap Power Point Chpt2Ap Power Point Chpt2
Ap Power Point Chpt2
 
Unit v
Unit vUnit v
Unit v
 
Python Basics by Akanksha Bali
Python Basics by Akanksha BaliPython Basics by Akanksha Bali
Python Basics by Akanksha Bali
 
Python Data-Types
Python Data-TypesPython Data-Types
Python Data-Types
 
Values and Data types in python
Values and Data types in pythonValues and Data types in python
Values and Data types in python
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
 
11 Unit 1 Chapter 02 Python Fundamentals
11  Unit 1 Chapter 02 Python Fundamentals11  Unit 1 Chapter 02 Python Fundamentals
11 Unit 1 Chapter 02 Python Fundamentals
 
Ap Power Point Chpt3
Ap Power Point Chpt3Ap Power Point Chpt3
Ap Power Point Chpt3
 
Introduction to Python programming Language
Introduction to Python programming LanguageIntroduction to Python programming Language
Introduction to Python programming Language
 
Cpu-fundamental of C
Cpu-fundamental of CCpu-fundamental of C
Cpu-fundamental of C
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and comments
 
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
 
358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3
 

Similar to Machine learning session3(intro to python)

1691912901477_Python_Basics and list,tuple,string.pptx
1691912901477_Python_Basics and list,tuple,string.pptx1691912901477_Python_Basics and list,tuple,string.pptx
1691912901477_Python_Basics and list,tuple,string.pptx
KUSHSHARMA630049
 
Python for Physical Science.pdf
Python for Physical Science.pdfPython for Physical Science.pdf
Python for Physical Science.pdf
MarilouANDERSON
 
Python ppt
Python pptPython ppt
PPt Revision of the basics of python1.pptx
PPt Revision of the basics of python1.pptxPPt Revision of the basics of python1.pptx
PPt Revision of the basics of python1.pptx
tcsonline1222
 
Python lab basics
Python lab basicsPython lab basics
Python lab basics
Abi_Kasi
 
Automation Testing theory notes.pptx
Automation Testing theory notes.pptxAutomation Testing theory notes.pptx
Automation Testing theory notes.pptx
NileshBorkar12
 
Top Most Python Interview Questions.pdf
Top Most Python Interview Questions.pdfTop Most Python Interview Questions.pdf
Top Most Python Interview Questions.pdf
Datacademy.ai
 
Spsl iv unit final
Spsl iv unit  finalSpsl iv unit  final
Spsl iv unit final
Sasidhar Kothuru
 
Spsl iv unit final
Spsl iv unit  finalSpsl iv unit  final
Spsl iv unit final
Sasidhar Kothuru
 
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualize
IruolagbePius
 
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
PART - 1  Python Introduction- Variables- Data types - Numeric- String- Boole...PART - 1  Python Introduction- Variables- Data types - Numeric- String- Boole...
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
manikamr074
 
Python fundamentals
Python fundamentalsPython fundamentals
Python fundamentals
natnaelmamuye
 
Data structures using C
Data structures using CData structures using C
Data structures using C
Pdr Patnaik
 
Ds12 140715025807-phpapp02
Ds12 140715025807-phpapp02Ds12 140715025807-phpapp02
Ds12 140715025807-phpapp02
Salman Qamar
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
Mufaddal Nullwala
 
Basic of Python- Hands on Session
Basic of Python- Hands on SessionBasic of Python- Hands on Session
Basic of Python- Hands on Session
Dharmesh Tank
 
An overview on python commands for solving the problems
An overview on python commands for solving the problemsAn overview on python commands for solving the problems
An overview on python commands for solving the problems
Ravikiran708913
 
BASICS OF PYTHON usefull for the student who would like to learn on their own
BASICS OF PYTHON usefull for the student who would like to learn on their ownBASICS OF PYTHON usefull for the student who would like to learn on their own
BASICS OF PYTHON usefull for the student who would like to learn on their own
Nandini485510
 
venkatesh.pptx
venkatesh.pptxvenkatesh.pptx
venkatesh.pptx
KishoreRedla
 
Python - Module 1.ppt
Python - Module 1.pptPython - Module 1.ppt
Python - Module 1.ppt
jaba kumar
 

Similar to Machine learning session3(intro to python) (20)

1691912901477_Python_Basics and list,tuple,string.pptx
1691912901477_Python_Basics and list,tuple,string.pptx1691912901477_Python_Basics and list,tuple,string.pptx
1691912901477_Python_Basics and list,tuple,string.pptx
 
Python for Physical Science.pdf
Python for Physical Science.pdfPython for Physical Science.pdf
Python for Physical Science.pdf
 
Python ppt
Python pptPython ppt
Python ppt
 
PPt Revision of the basics of python1.pptx
PPt Revision of the basics of python1.pptxPPt Revision of the basics of python1.pptx
PPt Revision of the basics of python1.pptx
 
Python lab basics
Python lab basicsPython lab basics
Python lab basics
 
Automation Testing theory notes.pptx
Automation Testing theory notes.pptxAutomation Testing theory notes.pptx
Automation Testing theory notes.pptx
 
Top Most Python Interview Questions.pdf
Top Most Python Interview Questions.pdfTop Most Python Interview Questions.pdf
Top Most Python Interview Questions.pdf
 
Spsl iv unit final
Spsl iv unit  finalSpsl iv unit  final
Spsl iv unit final
 
Spsl iv unit final
Spsl iv unit  finalSpsl iv unit  final
Spsl iv unit final
 
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualize
 
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
PART - 1  Python Introduction- Variables- Data types - Numeric- String- Boole...PART - 1  Python Introduction- Variables- Data types - Numeric- String- Boole...
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
 
Python fundamentals
Python fundamentalsPython fundamentals
Python fundamentals
 
Data structures using C
Data structures using CData structures using C
Data structures using C
 
Ds12 140715025807-phpapp02
Ds12 140715025807-phpapp02Ds12 140715025807-phpapp02
Ds12 140715025807-phpapp02
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
 
Basic of Python- Hands on Session
Basic of Python- Hands on SessionBasic of Python- Hands on Session
Basic of Python- Hands on Session
 
An overview on python commands for solving the problems
An overview on python commands for solving the problemsAn overview on python commands for solving the problems
An overview on python commands for solving the problems
 
BASICS OF PYTHON usefull for the student who would like to learn on their own
BASICS OF PYTHON usefull for the student who would like to learn on their ownBASICS OF PYTHON usefull for the student who would like to learn on their own
BASICS OF PYTHON usefull for the student who would like to learn on their own
 
venkatesh.pptx
venkatesh.pptxvenkatesh.pptx
venkatesh.pptx
 
Python - Module 1.ppt
Python - Module 1.pptPython - Module 1.ppt
Python - Module 1.ppt
 

More from Abhimanyu Dwivedi

Deepfakes videos
Deepfakes videosDeepfakes videos
Deepfakes videos
Abhimanyu Dwivedi
 
John mc carthy contribution to AI
John mc carthy contribution to AIJohn mc carthy contribution to AI
John mc carthy contribution to AI
Abhimanyu Dwivedi
 
Machine learning session9(clustering)
Machine learning   session9(clustering)Machine learning   session9(clustering)
Machine learning session9(clustering)
Abhimanyu Dwivedi
 
Machine learning session8(svm nlp)
Machine learning   session8(svm nlp)Machine learning   session8(svm nlp)
Machine learning session8(svm nlp)
Abhimanyu Dwivedi
 
Machine learning session7(nb classifier k-nn)
Machine learning   session7(nb classifier k-nn)Machine learning   session7(nb classifier k-nn)
Machine learning session7(nb classifier k-nn)
Abhimanyu Dwivedi
 
Machine learning session6(decision trees random forrest)
Machine learning   session6(decision trees random forrest)Machine learning   session6(decision trees random forrest)
Machine learning session6(decision trees random forrest)
Abhimanyu Dwivedi
 
Machine learning session5(logistic regression)
Machine learning   session5(logistic regression)Machine learning   session5(logistic regression)
Machine learning session5(logistic regression)
Abhimanyu Dwivedi
 
Machine learning session4(linear regression)
Machine learning   session4(linear regression)Machine learning   session4(linear regression)
Machine learning session4(linear regression)
Abhimanyu Dwivedi
 
Machine learning session2
Machine learning   session2Machine learning   session2
Machine learning session2
Abhimanyu Dwivedi
 
Machine learning session1
Machine learning   session1Machine learning   session1
Machine learning session1
Abhimanyu Dwivedi
 
Data analytics with python introductory
Data analytics with python introductoryData analytics with python introductory
Data analytics with python introductory
Abhimanyu Dwivedi
 
Housing price prediction
Housing price predictionHousing price prediction
Housing price prediction
Abhimanyu Dwivedi
 

More from Abhimanyu Dwivedi (12)

Deepfakes videos
Deepfakes videosDeepfakes videos
Deepfakes videos
 
John mc carthy contribution to AI
John mc carthy contribution to AIJohn mc carthy contribution to AI
John mc carthy contribution to AI
 
Machine learning session9(clustering)
Machine learning   session9(clustering)Machine learning   session9(clustering)
Machine learning session9(clustering)
 
Machine learning session8(svm nlp)
Machine learning   session8(svm nlp)Machine learning   session8(svm nlp)
Machine learning session8(svm nlp)
 
Machine learning session7(nb classifier k-nn)
Machine learning   session7(nb classifier k-nn)Machine learning   session7(nb classifier k-nn)
Machine learning session7(nb classifier k-nn)
 
Machine learning session6(decision trees random forrest)
Machine learning   session6(decision trees random forrest)Machine learning   session6(decision trees random forrest)
Machine learning session6(decision trees random forrest)
 
Machine learning session5(logistic regression)
Machine learning   session5(logistic regression)Machine learning   session5(logistic regression)
Machine learning session5(logistic regression)
 
Machine learning session4(linear regression)
Machine learning   session4(linear regression)Machine learning   session4(linear regression)
Machine learning session4(linear regression)
 
Machine learning session2
Machine learning   session2Machine learning   session2
Machine learning session2
 
Machine learning session1
Machine learning   session1Machine learning   session1
Machine learning session1
 
Data analytics with python introductory
Data analytics with python introductoryData analytics with python introductory
Data analytics with python introductory
 
Housing price prediction
Housing price predictionHousing price prediction
Housing price prediction
 

Recently uploaded

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 

Recently uploaded (20)

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 

Machine learning session3(intro to python)

  • 1. Learning to Program (…and a bit about ‘Life’)
  • 2. 2 What is a Computer Program? © 2014 All Rights Reserved Confidential A program is a sequence of instructions to perform a computational task. Essentially, any computer program (however complex it may get), almost always is a combination of below basic instructions:  Input  Output  Mathematical Operation  Conditional execution  Repetition Programming languages are formal languages that have been designed to express computations.
  • 3. 3 Python © 2015 All Rights Reserved Confidential Python is an easy to learn powerful programming language. Some features of python are: • Simple • Interpreted • Free and Open Source • High Level • Portable • Object Oriented • Extensible
  • 4. 4 Interpreter vs Complier © 2015 All Rights Reserved Confidential • Programs written in high-level languages have to be converted into low-level language for the computer to understand them. • 2 kinds of program that convert high level source code to low level are: Interpreter and Compiler • An interpreter translates the source code line by line. • A compiler reads the entire program and translates it completely before the program runs. The source code is compiled into an object code which is then executed. Once a program is complied, it can be executed many times without the need of compilation. Source Code Interpreter Output Source Code Compiler OutputObject Code Executor
  • 5. 5 Basics of Python © 2014 All Rights Reserved Confidential Comments: These are the descriptive text that is put in the program so that the person who is reading it, can understand what a particular statement or a block of statements is doing. ‘#’ symbol is used to mark comments e.g Print(“My name is Jack) # Using print() function to print name Comments are not compiled. The compiler just ignores everything which is written after # Numbers: Numbers are of 2 types – integers and floats. 2 is an integer but 2.34 is a floating point number Strings: A string is a sequence of characters. Strings are specified either using single-quotes or double quotes. Variables: A variable is a name that refers to a value. E.g n = 17 i.e The value 17 is assigned to a variable named “n”. In python, variables names begin with a letter and can not contain special characters. Also keywords can not be used as variable names. To know the type of variables, use the function type()
  • 6. 6 Basics of Python..(Contd) © 2014 All Rights Reserved Confidential Operators: Operators are special symbols that represent computations like addition or subtraction + addition - Subtraction * Multiplication / Division ** Power // Integer Division % Mod Operation Expression: An expression is a combination of values, variables and operators.
  • 7. 7 Its refers to the methodology of programming where programs are made of object definitions and function definitions and most of the computation is expressed in terms of operations on objects. Each object definition corresponds to some object or concept in real world and the functions that operate on that object correspond to the ways real-world object interacts. • Organizing your program to combine data and functionality • Class creates a new type where objects are instances of the class. • Class is like a blueprint or a template • Variables that belong to an object or class are referred to as fields. • Functions that belong to a class are called Methods • Fields and Methods are known as attributes of a class. • Fields are of two types - they can belong to each instance/object of the class or they can belong to the class itself. They are called instance variables and class variables respectively Object Oriented Programming © 2014 All Rights Reserved Confidential
  • 8. 8 Functions © 2014 All Rights Reserved Confidential • A function is a named sequence of statements that performs a computation. • A module is a file that contains a collection of related functions. • Packages are just folders to hierarchically organize modules. • Each package contains a bunch of Python scripts. Each script is a module. Examples of packages are Numpy, sckit-learn, pandas etc
  • 9. 9 Control Flow - If © 2014 All Rights Reserved Confidential 3 control flow statements in Python – If, while and for If statement is used to check a condition: Cp = int(input(“Enter the cost price: ”)) Sp = int(input(“Enter the selling price: ”)) If(sp>cp): print(“Congratulations! You have made a profit”) Elif(sp<cp): print(“Sorry! You are in loss”) Else: print(“No profit. No Loss”)
  • 10. 10 Control Flow - While © 2014 All Rights Reserved Confidential While statement is used to repeatedly execute a block of statements as long as a condition is true. # Read a number. Print the square of all numbers from 1 upto N n= int(input("Enter a number: ")) # Initial Condition i = 1 while(i<=n): print(i*i) i = i+1
  • 11. 11 Control Flow – For Loop © 2014 All Rights Reserved Confidential For statement is also used to repeatedly execute a block of statements as long as a condition is true. # Read a number. Print the square of all numbers from 1 upto N n= int(input("Enter a number: ")) # Initial Condition For I in range(1, N+1): print(i*i)
  • 12. 12 Data Structures - Lists © 2014 All Rights Reserved Confidential Lists : A list is a data structure that holds an ordered collection of items i.e. you can store a sequence of items in a list. Once you have created a list, you can add, remove or search for items in the list. Since we can add and remove items, we say that a list is a mutable data type i.e. this type can be altered. shoplist = ['apple', 'mango', 'carrot', 'banana'] print('I have', len(shoplist), 'items to purchase.') print('These items are:', end=' ') for item in shoplist: print(item, end=' ') print('nI also have to buy rice.') shoplist.append('rice') print('My shopping list is now', shoplist) print('I will sort my list now') shoplist.sort() print('Sorted shopping list is', shoplist)
  • 13. 13 Data Structures - Lists © 2014 All Rights Reserved Confidential print('The first item I will buy is', shoplist[0]) olditem = shoplist[0] del shoplist[0] print('I bought the', olditem) print('My shopping list is now', shoplist) # To print unique elements of a list Mylist=list(set(mylist)) # To convert all elements of a list into numbers: mylist=[int(x) for x in mylist] # List Indexing: fruits = [‘Orange’, ‘Banana’, ‘Apple’, ‘Pear’] fruits[1] gives second element fruits[-1] gives last element
  • 14. 14 Data Structures - Lists © 2014 All Rights Reserved Confidential # List Slicing: To select multiple elements from a list : Mylist[start:end] fruits = [‘Orange’, ‘Banana’, ‘Apple’, ‘Pear’] fruits[1:3] gives [‘Banana’, ‘Apple’]. The elements are returned with index “start” upto index “end-1” Fruits[1:] gives [‘Banana’, ‘Apple’, ‘Pear’] Fruits[:3] gives [‘Orange’, ‘Banana’, ‘Apple’] # Print last 3 elements: Fruits[-3:]
  • 15. 15 Data Structures – Nested Lists © 2014 All Rights Reserved Confidential A list can contain other lists >>> x = [["a", "b", "c"], ["d", "e", "f"], ["g", "h", "i"]] X[1] results ["d", "e", "f"] X[1][2] results “f”
  • 16. 16 Data Structures - Dictionary © 2014 All Rights Reserved Confidential A dictionary is like an address-book where you can find the address or contact details of a person by knowing only his/her name i.e. we associate keys (name) with values (details). Note that the key must be unique just like you cannot find out the correct information if you have two persons with the exact same name. Note that you can use only immutable objects (like strings) for the keys of a dictionary but you can use either immutable or mutable objects for the values of the dictionary. This basically translates to say that you should use only simple objects for keys.
  • 17. 17 Data Structures - Dictionary © 2014 All Rights Reserved Confidential ab = { ‘Gaurav' : ‘gaurav@itbodhi.com', 'Larry' : 'larry@wall.org', 'Matsumoto' : 'matz@ruby-lang.org', 'Spammer' : 'spammer@hotmail.com' } print(“Gaurav's address is", ab[‘Gaurav']) # Deleting a key-value pair del ab['Spammer'] print('nThere are {0} contacts in the address-bookn'.format(len(ab))) for name, address in ab.items(): print('Contact {0} at {1}'.format(name, address)) # Adding a key-value pair ab['Guido'] = 'guido@python.org' if 'Guido' in ab: print("nGuido's address is", ab['Guido'])