SlideShare uma empresa Scribd logo
1 de 58
Introduction to Python Programming
What is Python?
⚫Python isaclear andpowerfulobject-oriented programming
language,comparable to Perl, Ruby,Scheme,or Java.
**
2
History
⚫Python is a high-level, interpreted scripting language developed
in the late 1980s by Guido van Rossum at the National Research
Institute for Mathematics and Computer Science in the
Netherlands.
⚫The initial version was published at the alt.sources newsgroup in
1991, and version 1.0 wasreleased in 1994.
**
3
⚫Python 2.0 was released in 2000, and the 2.x versions were
the prevalent releasesuntil December 2008.
⚫At that time, the development team made the decision to
release version 3.0, which contained a few relatively small
but significant changes that were not backward compatible
with the 2.x versions.
⚫Python 2 and 3 are very similar, and some features of Python
3 have been backported to Python 2. But in general, they
remain not quite compatible.
(Source: https://realpython.com/python-introduction/)
**
4
⚫The name Python, by the way, derives not from the snake,
but from the British comedy troupe Monty Python’s Flying
Circus,of which Guido was,and presumably still is, afan.
**
5
Some of Python's notable features:
⚫ Uses an elegant syntax, making the programs you write easier to read.
⚫ Is an easy-to-use language that makes it simple to get your program working.
⚫ Comes with a large standard library that supports many common
programming tasks such as connecting to web servers, searching text with
regular expressions, reading and modifying files.
⚫ Python's interactive mode makes it easy to test short snippets of code.There's
also abundled development environment called IDLE.
⚫ Is easily extended by adding new modules implemented in a compiled
language such asC or C++.
(Source: https://wiki.python.org/moin/BeginnersGuide/Overview)
**
6
⚫ Can also be embedded into an application to provide a programmable
interface.
⚫ Runs anywhere, including Mac OS X, Windows, Linux, and Unix,
with unofficialbuilds also availableforAndroid and iOS.
⚫ Is free software in two senses. It doesn't cost anything to download or
use Python, or to include it in your application.
⚫ Python can also be freely modified and re-distributed, because while the
language is copyrighted it's available under an open source license.
(Source:https://wiki.python.org/moin/BeginnersGuide/Overview)
7
Some programming-language features:
⚫ A variety of basic data types are available: numbers (floating point, complex, and
unlimited-length long integers), strings (bothASCIIand Unicode),lists,and dictionaries.
⚫ Python supports object-oriented programming with classes and multiple
inheritance.
⚫ Code can be grouped into modules and packages.
⚫ The language supports raising and catching exceptions, resulting in cleaner error
handling.
⚫ Data types are strongly and dynamically typed. Mixing incompatible types (e.g.
attempting to add a string and a number) causes an exception to be raised, so errors are
caught sooner.
⚫ Python contains advanced programming features such as generators and list
comprehensions.
⚫ Python's automatic memory management frees you from having to manually
allocate and free memoryin your code.
(Source: https://wiki.python.org/moin/BeginnersGuide/Overview)
8
Module 1:
⚫Chapter 1:Whyshould you learn to write programs
⚫Chapter 2:Variables,expressions and statements
⚫Chapter 3: Conditional execution
⚫Chapter 4: Functions
9
Chapter 1:
Whyshould you learn to write programs
⚫1.1 Creativity and motivation
⚫1.2 Computer hardware architecture
⚫1.3 Understanding programming
⚫1.4W
ords and sentences
⚫1.5 Conversingwith Python
⚫1.6Terminology:interpreter and compiler
⚫1.7Writing aprogram
⚫1.8What is aprogram?
⚫1.9The building blocksof programs
⚫1.10What could possibly go wrong?
10
⚫1.1 Creativity and motivation
Computer hardware architecture
12
⚫1.3 Understanding programming
⚫1.4Words and sentences
⚫1.5 Conversing with Python
Terminology:
Interpreter and Compiler
⚫Python is a high-level language intended to be relatively
straightforward for humans to read and write and for computers to
read and process. The actual hardware inside the Central Processing
Unit (CPU) does not understand anyof these high-level languages.
⚫The CPU understands alanguage called machine language.
⚫Since machine language is tied to the computer hardware, machine
language is not portableacross different typesof hardware.
14
Translator
⚫Allows programmers to write in high-level languages like Python
or JavaScript and convert the programs to machine language for
actual execution bythe CPU.
⚫These programming language translators fall into two general
categories:
(1) interpreters and
(2) compilers.
⚫Programs written in high-level languages can be moved between
different computers by using a different interpreter on the new
machine or recompiling the code to create a machine language
version of the program for the new machine
15
1) Interpreter:
⚫ An interpreter reads the source code of the program as written by the
programmer, parses the source code,and interprets the instructions on the fly.
⚫ Python is an interpreter and when we are running Python interactively, we can
type a line of Python (a sentence) and Python processes it immediately and is
readyfor us to type another line of Python.
>>> x = 6
>>> print(x)
6
>>> y = x * 7
>>> print(y)
42
⚫ Even though we are typing these commands into Python one line at a time,
Python is treating them as an ordered sequence of statements with later
statements able to retrieve data created in earlier statements. We are writing our
first simple paragraph with four sentences in a logical and meaningful order. It is
the nature of an interpreter to be able to have an interactive conversation as shown
above.
16
2) Compiler:
⚫Compilers needs to be handed the entire program in a file, and
then it runs a process to translate the high-level source code into
machine language and then the compiler puts the resulting machine
language into afile for later execution.
⚫If you have a Windows system, often these executable machine
language programs have a suffix of “.exe” or “.dll” which stand for
“executable” and “dynamic link library” respectively. In Linux and
Macintosh,there is no suffix that uniquely marks afile asexecutable.
**
17
⚫The Python interpreter is written in a high-level language
called“C”.
⚫So Python is a program itself and it is compiled into machine
code. When you installed Python on your computer (or the
vendor installed it), you copied a machine-code copy of the
translated Python program onto your system. In Windows,
the executable machine code for Python itself is likely in a
file with aname like: C: Python35 python.exe
⚫Click
18
General types of errors
⚫Syntax error: means that you have violated the “grammar” rules
of Python.
⚫Logic errors: Alogic error is when your program has good syntax
but there is a mistake in the order of the statements or perhaps a
mistake in how the statements relate to one another
⚫Semantic errors: A semantic error is when your description of
the steps to take is syntactically perfect and in the right order, but
there is simply a mistake in the program. The program is perfectly
correct but it does not do what youintended for it to do.
19
The building blocks of programs
⚫ Input: Get data from the “outside world”. This might be reading data from a
file, or even some kind of sensor like a microphone or GPS. In our initial
programs,our input will come from the user typing data on the keyboard.
⚫ Output: Display the results of the program on a screen or store them in a file
or perhaps write them to adevice like aspeaker to playmusic or speak text.
⚫ Sequential execution: Perform statements one after another in the order
theyare encountered in the script.
⚫ Conditional execution: Check for certain conditions and then execute or
skip asequence of statements.
⚫ Repeated execution: Perform some set of statements repeatedly, usually
with some variation.
⚫ Reuse: Write a set of instructions once and give them a name and then reuse
those instructions asneeded throughout your program.
20
Writinga program
⚫Script: When we want to write a program, we use a text
editor to write the Python instructions into a file, which is
called ascript.
⚫Byconvention,Python scripts havenames that end with .py
⚫To execute the script, you have to tell the Python interpreter
the name of the file.
21
Installing the Python
⚫Before you can converse with Python, you must first install
the Python software on your computer and learn how to
start Python on your computer.
⚫https://www.python.org/downloads/
⚫https://www.anaconda.com/distribution/
22
**
21
24 **
Python Shell
⚫Python is most commonly translated byuse of an interpreter.
⚫Thus python provides the very useful ability to execute in
interactive mode.
⚫The window that provides this interaction is referred to as
the python shell.
⚫Although working in the python shell is convenient, the
entered code is not saved.
25
Python Shell
**
26
IDLE
⚫Integrated Development Environment is a bundle set of
software tools for program development.
⚫This typicallyincludes
⚫Editor: for creating and modifying programs
⚫Translator: for executing programs
⚫Program debugger: takes control of the execution of a program
to aidin finding program errors
**
27
IDLE
**
28
Anaconda Navigator
**
29
⚫At some point, you will be in a terminal or command window
and you will type python or python3 and the Python interpreter
will start executing in interactive mode and appear somewhat as
follows:
**
30
⚫The >>> (chevron) prompt is the Python interpreter’s way of
asking you, “What do you want me to do next?” Python is ready
to have aconversation with you.
>>> quit()
⚫The proper way to say “good-bye” to Python is to enter quit() at
the interactive chevron >>> prompt.
**
31
⚫In aUnix or Windows command window, you would type
python hello.py as follows:
csev$ cat hello.py
print('Hello world!')
csev$ python hello.py
Hello world!
csev$
**
32
Conversing with Python
⚫print()
**
33
print DEMO
**
34
**
35
**
36
The Python Standard Library
⚫The Python Standard Library is a collection of built-in
modules, each providing specific functionalities beyond what
is included in the core part of Python.
⚫In order to utilize the capabilities of a given module in a
specific program, an import statement is used.
**
37
Keywords in python
import keyword
keyword.kwlist
**
38
False None True and as
assert async await break
class continue def del
elif else except finally
for from global if
import in is lambda
nonlocal not or pass
raise return try while
with yield
**
39
Comments
# is used for commenting
Example:
#print(hello)
**
40
Chapter 2:
Variables, expressions and statements
1. Values and types
2. Variables
3. Variable names and keywords
4. Statements
5. Operators and operands
6. Expressions ------- Combination of values, variable &
operators
7. Order of operations
8. Modulus operator
9. String operations
10. Asking the user for input
11. Comments
Values and type
print(4)
print(4.2)
print(‘hello’)
print(4,00,000)
Print(400000)
Variables
n=10
Print(n)
pi=3.142
print(pi)
Variable names and keywords
False None True and as
assert async await break
class continue def del
elif else except finally
for from global if
import in is lambda
nonlocal not or pass
raise return try while
with yield
Operators and operands
*, -,+, / , **, //
Example: m=59
m/60
m=59
m//60
>>> x = 1 + 2 ** 3 / 4 * 5
>>> print(x)
11
>>>
1 + 2 ** 3 / 4 * 5
1 + 8 / 4 * 5
1 + 2 * 5
1 + 10
11
Parenthesis
Power
Multiplication
Addition
Left to Right
Modulus operator
%
x=10
y=x%3
print(y)
String Operations
l=10
m=15
Print(l+m)
l=’10’
m=‘15’
print(l+m)
k=‘python’
m=4
print(k*m)
Asking the user for input
a=input()
print(a)
b=input(‘enter the number:’)
print(b)
p=‘what is the speed of bike’
speed=input(p)
print(int(speed)+10)
Chapter 3
Conditional Execution
• Boolean expressions
• Logical expressions
• Conditional execution
• Alternative execution
• Chained conditionals
• Nested conditionals
• Catching exceptions using try and except
• Short-circuit evaluation of logical expressions
Ex: x >= 2 and (x/y) > 2
Chapter 4 Functions
• Function Calls
• Built-in functions
• Type conversion functions
• Random numbers ---- Non Deterministic
• Math functions
• Adding new functions
• Definitions and uses
• Flow of execution
• Parameters and arguments
• Fruitful functions and void functions
• Why functions?
Math Functions
1Deg × π/180
Adding new functions
Definitions and uses
Parameters and arguments
• Flow of execution
def print_lyrics(): print("I'm a lumberjack,
and I'm okay.") print('I sleep all night and I
work all day.')def repeat_lyrics():
print_lyrics() print_lyrics()repeat_lyrics()

Mais conteúdo relacionado

Semelhante a Module1-Chapter1_ppt.pptx

introduction of python in data science
introduction of python in data scienceintroduction of python in data science
introduction of python in data sciencebhavesh lande
 
Introduction to python for Beginners
Introduction to python for Beginners Introduction to python for Beginners
Introduction to python for Beginners Sujith Kumar
 
Python Training in Pune - Ethans Tech Pune
Python Training in Pune - Ethans Tech PunePython Training in Pune - Ethans Tech Pune
Python Training in Pune - Ethans Tech PuneEthan's Tech
 
Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialQA TrainingHub
 
Introduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdfIntroduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdfVaibhavKumarSinghkal
 
Python_final_print_vison_academy_9822506209.pdf
Python_final_print_vison_academy_9822506209.pdfPython_final_print_vison_academy_9822506209.pdf
Python_final_print_vison_academy_9822506209.pdfVisionAcademyProfSac
 
Web Programming UNIT VIII notes
Web Programming UNIT VIII notesWeb Programming UNIT VIII notes
Web Programming UNIT VIII notesBhavsingh Maloth
 
Python Programming and ApplicationsUnit-1.docx
Python Programming and ApplicationsUnit-1.docxPython Programming and ApplicationsUnit-1.docx
Python Programming and ApplicationsUnit-1.docxManohar k
 
Phython Programming Language
Phython Programming LanguagePhython Programming Language
Phython Programming LanguageR.h. Himel
 
Python Programming-Lesson 1- Installation and Environmental Set-up.pptx
Python Programming-Lesson 1- Installation and Environmental Set-up.pptxPython Programming-Lesson 1- Installation and Environmental Set-up.pptx
Python Programming-Lesson 1- Installation and Environmental Set-up.pptxBautistaAljhonG
 
Python-00 | Introduction and installing
Python-00 | Introduction and installingPython-00 | Introduction and installing
Python-00 | Introduction and installingMohd Sajjad
 
Ali alshehri c++_comparison between c++&python
Ali alshehri c++_comparison between c++&pythonAli alshehri c++_comparison between c++&python
Ali alshehri c++_comparison between c++&pythonAliAAAlshehri
 
Python_final_print_batch_II_vision_academy.pdf
Python_final_print_batch_II_vision_academy.pdfPython_final_print_batch_II_vision_academy.pdf
Python_final_print_batch_II_vision_academy.pdfbhagyashri686896
 

Semelhante a Module1-Chapter1_ppt.pptx (20)

introduction of python in data science
introduction of python in data scienceintroduction of python in data science
introduction of python in data science
 
Introduction to python for Beginners
Introduction to python for Beginners Introduction to python for Beginners
Introduction to python for Beginners
 
Python Training in Pune - Ethans Tech Pune
Python Training in Pune - Ethans Tech PunePython Training in Pune - Ethans Tech Pune
Python Training in Pune - Ethans Tech Pune
 
Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python Tutorial
 
python unit2.pptx
python unit2.pptxpython unit2.pptx
python unit2.pptx
 
Cmpe202 01 Research
Cmpe202 01 ResearchCmpe202 01 Research
Cmpe202 01 Research
 
Introduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdfIntroduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdf
 
Chapter - 1.pptx
Chapter - 1.pptxChapter - 1.pptx
Chapter - 1.pptx
 
Python Programming Draft PPT.pptx
Python Programming Draft PPT.pptxPython Programming Draft PPT.pptx
Python Programming Draft PPT.pptx
 
Python_final_print_vison_academy_9822506209.pdf
Python_final_print_vison_academy_9822506209.pdfPython_final_print_vison_academy_9822506209.pdf
Python_final_print_vison_academy_9822506209.pdf
 
Summer Training Project.pdf
Summer Training Project.pdfSummer Training Project.pdf
Summer Training Project.pdf
 
Web Programming UNIT VIII notes
Web Programming UNIT VIII notesWeb Programming UNIT VIII notes
Web Programming UNIT VIII notes
 
Python Programming and ApplicationsUnit-1.docx
Python Programming and ApplicationsUnit-1.docxPython Programming and ApplicationsUnit-1.docx
Python Programming and ApplicationsUnit-1.docx
 
Phython Programming Language
Phython Programming LanguagePhython Programming Language
Phython Programming Language
 
Research paper on python by Rj
Research paper on python by RjResearch paper on python by Rj
Research paper on python by Rj
 
Python Programming-Lesson 1- Installation and Environmental Set-up.pptx
Python Programming-Lesson 1- Installation and Environmental Set-up.pptxPython Programming-Lesson 1- Installation and Environmental Set-up.pptx
Python Programming-Lesson 1- Installation and Environmental Set-up.pptx
 
Python-00 | Introduction and installing
Python-00 | Introduction and installingPython-00 | Introduction and installing
Python-00 | Introduction and installing
 
Python
PythonPython
Python
 
Ali alshehri c++_comparison between c++&python
Ali alshehri c++_comparison between c++&pythonAli alshehri c++_comparison between c++&python
Ali alshehri c++_comparison between c++&python
 
Python_final_print_batch_II_vision_academy.pdf
Python_final_print_batch_II_vision_academy.pdfPython_final_print_batch_II_vision_academy.pdf
Python_final_print_batch_II_vision_academy.pdf
 

Último

Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spaintimesproduction05
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSrknatarajan
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 

Último (20)

Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 

Module1-Chapter1_ppt.pptx

  • 2. What is Python? ⚫Python isaclear andpowerfulobject-oriented programming language,comparable to Perl, Ruby,Scheme,or Java. ** 2
  • 3. History ⚫Python is a high-level, interpreted scripting language developed in the late 1980s by Guido van Rossum at the National Research Institute for Mathematics and Computer Science in the Netherlands. ⚫The initial version was published at the alt.sources newsgroup in 1991, and version 1.0 wasreleased in 1994. ** 3
  • 4. ⚫Python 2.0 was released in 2000, and the 2.x versions were the prevalent releasesuntil December 2008. ⚫At that time, the development team made the decision to release version 3.0, which contained a few relatively small but significant changes that were not backward compatible with the 2.x versions. ⚫Python 2 and 3 are very similar, and some features of Python 3 have been backported to Python 2. But in general, they remain not quite compatible. (Source: https://realpython.com/python-introduction/) ** 4
  • 5. ⚫The name Python, by the way, derives not from the snake, but from the British comedy troupe Monty Python’s Flying Circus,of which Guido was,and presumably still is, afan. ** 5
  • 6. Some of Python's notable features: ⚫ Uses an elegant syntax, making the programs you write easier to read. ⚫ Is an easy-to-use language that makes it simple to get your program working. ⚫ Comes with a large standard library that supports many common programming tasks such as connecting to web servers, searching text with regular expressions, reading and modifying files. ⚫ Python's interactive mode makes it easy to test short snippets of code.There's also abundled development environment called IDLE. ⚫ Is easily extended by adding new modules implemented in a compiled language such asC or C++. (Source: https://wiki.python.org/moin/BeginnersGuide/Overview) ** 6
  • 7. ⚫ Can also be embedded into an application to provide a programmable interface. ⚫ Runs anywhere, including Mac OS X, Windows, Linux, and Unix, with unofficialbuilds also availableforAndroid and iOS. ⚫ Is free software in two senses. It doesn't cost anything to download or use Python, or to include it in your application. ⚫ Python can also be freely modified and re-distributed, because while the language is copyrighted it's available under an open source license. (Source:https://wiki.python.org/moin/BeginnersGuide/Overview) 7
  • 8. Some programming-language features: ⚫ A variety of basic data types are available: numbers (floating point, complex, and unlimited-length long integers), strings (bothASCIIand Unicode),lists,and dictionaries. ⚫ Python supports object-oriented programming with classes and multiple inheritance. ⚫ Code can be grouped into modules and packages. ⚫ The language supports raising and catching exceptions, resulting in cleaner error handling. ⚫ Data types are strongly and dynamically typed. Mixing incompatible types (e.g. attempting to add a string and a number) causes an exception to be raised, so errors are caught sooner. ⚫ Python contains advanced programming features such as generators and list comprehensions. ⚫ Python's automatic memory management frees you from having to manually allocate and free memoryin your code. (Source: https://wiki.python.org/moin/BeginnersGuide/Overview) 8
  • 9. Module 1: ⚫Chapter 1:Whyshould you learn to write programs ⚫Chapter 2:Variables,expressions and statements ⚫Chapter 3: Conditional execution ⚫Chapter 4: Functions 9
  • 10. Chapter 1: Whyshould you learn to write programs ⚫1.1 Creativity and motivation ⚫1.2 Computer hardware architecture ⚫1.3 Understanding programming ⚫1.4W ords and sentences ⚫1.5 Conversingwith Python ⚫1.6Terminology:interpreter and compiler ⚫1.7Writing aprogram ⚫1.8What is aprogram? ⚫1.9The building blocksof programs ⚫1.10What could possibly go wrong? 10
  • 11. ⚫1.1 Creativity and motivation
  • 13. ⚫1.3 Understanding programming ⚫1.4Words and sentences ⚫1.5 Conversing with Python
  • 14. Terminology: Interpreter and Compiler ⚫Python is a high-level language intended to be relatively straightforward for humans to read and write and for computers to read and process. The actual hardware inside the Central Processing Unit (CPU) does not understand anyof these high-level languages. ⚫The CPU understands alanguage called machine language. ⚫Since machine language is tied to the computer hardware, machine language is not portableacross different typesof hardware. 14
  • 15. Translator ⚫Allows programmers to write in high-level languages like Python or JavaScript and convert the programs to machine language for actual execution bythe CPU. ⚫These programming language translators fall into two general categories: (1) interpreters and (2) compilers. ⚫Programs written in high-level languages can be moved between different computers by using a different interpreter on the new machine or recompiling the code to create a machine language version of the program for the new machine 15
  • 16. 1) Interpreter: ⚫ An interpreter reads the source code of the program as written by the programmer, parses the source code,and interprets the instructions on the fly. ⚫ Python is an interpreter and when we are running Python interactively, we can type a line of Python (a sentence) and Python processes it immediately and is readyfor us to type another line of Python. >>> x = 6 >>> print(x) 6 >>> y = x * 7 >>> print(y) 42 ⚫ Even though we are typing these commands into Python one line at a time, Python is treating them as an ordered sequence of statements with later statements able to retrieve data created in earlier statements. We are writing our first simple paragraph with four sentences in a logical and meaningful order. It is the nature of an interpreter to be able to have an interactive conversation as shown above. 16
  • 17. 2) Compiler: ⚫Compilers needs to be handed the entire program in a file, and then it runs a process to translate the high-level source code into machine language and then the compiler puts the resulting machine language into afile for later execution. ⚫If you have a Windows system, often these executable machine language programs have a suffix of “.exe” or “.dll” which stand for “executable” and “dynamic link library” respectively. In Linux and Macintosh,there is no suffix that uniquely marks afile asexecutable. ** 17
  • 18. ⚫The Python interpreter is written in a high-level language called“C”. ⚫So Python is a program itself and it is compiled into machine code. When you installed Python on your computer (or the vendor installed it), you copied a machine-code copy of the translated Python program onto your system. In Windows, the executable machine code for Python itself is likely in a file with aname like: C: Python35 python.exe ⚫Click 18
  • 19. General types of errors ⚫Syntax error: means that you have violated the “grammar” rules of Python. ⚫Logic errors: Alogic error is when your program has good syntax but there is a mistake in the order of the statements or perhaps a mistake in how the statements relate to one another ⚫Semantic errors: A semantic error is when your description of the steps to take is syntactically perfect and in the right order, but there is simply a mistake in the program. The program is perfectly correct but it does not do what youintended for it to do. 19
  • 20. The building blocks of programs ⚫ Input: Get data from the “outside world”. This might be reading data from a file, or even some kind of sensor like a microphone or GPS. In our initial programs,our input will come from the user typing data on the keyboard. ⚫ Output: Display the results of the program on a screen or store them in a file or perhaps write them to adevice like aspeaker to playmusic or speak text. ⚫ Sequential execution: Perform statements one after another in the order theyare encountered in the script. ⚫ Conditional execution: Check for certain conditions and then execute or skip asequence of statements. ⚫ Repeated execution: Perform some set of statements repeatedly, usually with some variation. ⚫ Reuse: Write a set of instructions once and give them a name and then reuse those instructions asneeded throughout your program. 20
  • 21. Writinga program ⚫Script: When we want to write a program, we use a text editor to write the Python instructions into a file, which is called ascript. ⚫Byconvention,Python scripts havenames that end with .py ⚫To execute the script, you have to tell the Python interpreter the name of the file. 21
  • 22. Installing the Python ⚫Before you can converse with Python, you must first install the Python software on your computer and learn how to start Python on your computer. ⚫https://www.python.org/downloads/ ⚫https://www.anaconda.com/distribution/ 22
  • 23. ** 21
  • 24. 24 **
  • 25. Python Shell ⚫Python is most commonly translated byuse of an interpreter. ⚫Thus python provides the very useful ability to execute in interactive mode. ⚫The window that provides this interaction is referred to as the python shell. ⚫Although working in the python shell is convenient, the entered code is not saved. 25
  • 27. IDLE ⚫Integrated Development Environment is a bundle set of software tools for program development. ⚫This typicallyincludes ⚫Editor: for creating and modifying programs ⚫Translator: for executing programs ⚫Program debugger: takes control of the execution of a program to aidin finding program errors ** 27
  • 30. ⚫At some point, you will be in a terminal or command window and you will type python or python3 and the Python interpreter will start executing in interactive mode and appear somewhat as follows: ** 30
  • 31. ⚫The >>> (chevron) prompt is the Python interpreter’s way of asking you, “What do you want me to do next?” Python is ready to have aconversation with you. >>> quit() ⚫The proper way to say “good-bye” to Python is to enter quit() at the interactive chevron >>> prompt. ** 31
  • 32. ⚫In aUnix or Windows command window, you would type python hello.py as follows: csev$ cat hello.py print('Hello world!') csev$ python hello.py Hello world! csev$ ** 32
  • 35. ** 35
  • 36. ** 36
  • 37. The Python Standard Library ⚫The Python Standard Library is a collection of built-in modules, each providing specific functionalities beyond what is included in the core part of Python. ⚫In order to utilize the capabilities of a given module in a specific program, an import statement is used. ** 37
  • 38. Keywords in python import keyword keyword.kwlist ** 38
  • 39. False None True and as assert async await break class continue def del elif else except finally for from global if import in is lambda nonlocal not or pass raise return try while with yield ** 39
  • 40. Comments # is used for commenting Example: #print(hello) ** 40
  • 41. Chapter 2: Variables, expressions and statements 1. Values and types 2. Variables 3. Variable names and keywords 4. Statements 5. Operators and operands 6. Expressions ------- Combination of values, variable & operators 7. Order of operations 8. Modulus operator 9. String operations 10. Asking the user for input 11. Comments
  • 44. Variable names and keywords False None True and as assert async await break class continue def del elif else except finally for from global if import in is lambda nonlocal not or pass raise return try while with yield
  • 45. Operators and operands *, -,+, / , **, // Example: m=59 m/60 m=59 m//60
  • 46. >>> x = 1 + 2 ** 3 / 4 * 5 >>> print(x) 11 >>>
  • 47. 1 + 2 ** 3 / 4 * 5 1 + 8 / 4 * 5 1 + 2 * 5 1 + 10 11 Parenthesis Power Multiplication Addition Left to Right
  • 50. Asking the user for input a=input() print(a) b=input(‘enter the number:’) print(b) p=‘what is the speed of bike’ speed=input(p) print(int(speed)+10)
  • 51. Chapter 3 Conditional Execution • Boolean expressions • Logical expressions • Conditional execution • Alternative execution • Chained conditionals • Nested conditionals • Catching exceptions using try and except • Short-circuit evaluation of logical expressions Ex: x >= 2 and (x/y) > 2
  • 52. Chapter 4 Functions • Function Calls • Built-in functions • Type conversion functions • Random numbers ---- Non Deterministic • Math functions • Adding new functions • Definitions and uses • Flow of execution • Parameters and arguments • Fruitful functions and void functions • Why functions?
  • 54.
  • 57. Parameters and arguments • Flow of execution
  • 58. def print_lyrics(): print("I'm a lumberjack, and I'm okay.") print('I sleep all night and I work all day.')def repeat_lyrics(): print_lyrics() print_lyrics()repeat_lyrics()