SlideShare a Scribd company logo
Python Programming
(BCC302)
Introduction to Python
Brief History of Python
 Invented in the Netherlands, early 90s by Guido
van Rossum(February 20, 1991)
 Named after Monty Python
 Open sourced from the beginning
 Considered a scripting language, but is much more
 Scalable, object oriented and functional from the
beginning
 Used by Google from the beginning
 Increasingly popular
Python
Python is an open
source, object -
oriented, high-
level powerful
programming
language.
Developed by
Guido Van
Rossum in early
1990.
Python is
platform
independent
Introduction To Python Interpreter
A python program is read by a parser.
Python was designed to be highly readable language.
Python Program
Python program are composed of modules.
Modules contain statements.
Statements contain expressions.
Expressions create and process objects.
Features Of Python
Open source
Easy to learn
Major Uses Of Python
System
utilities
Web
development
Graphical
user
interface
Internet
scripting
Embedded
scripting
Major Uses Of Python
Database
access
and
programm
ing.
Game
programming
Rapid
prototyping
and
development
Distributed
programmin
g
Python Is Easy To Use
C program C ++ program Java
program
Python
program
#include <stdio.h>
int main (int
argc,char ** argv)
{
Printf (“welcome”);
}
#include<iostream >
int main()
{
Std:: cout
<<“welcome”<<std::e
ndl;
return0;
}
Public class
hello
{
Public static
voidmain(string
argv[])
{
System .out.
println(“welcom
e”);
}
}
Print (“welcome”)
Python Definition
Python is a high level programming language designed to be easy
to read and simple to implement.
Python is considered a scripting language.
Scripts written in python (.py files ) can be parsed and run
immediately.
Python Coding Style
Use 4 space per
indentation and
no tabs.
Do not mix tabs
and spaces.
Maximum line
length.
Python Coding Style
Use blank lines to
separate top level
function and class
definitions.
Inline comments
(should be
complete
sentences).
Use spaces around
expression and
statements.
Python Is Interactive
Python has an interactive console where you get a python prompt
and interact with interpreter directly.
• Interpreted
• Extendable
• Libraries
• supports
http://docs.python.org/
Introduction to python.pptx
Running Python
The Python Interpreter
 Typical Python implementations offer both an interpreter
and compiler
 Interactive interface to Python with a read-eval-print loop
[finin@linux2 ~]$ python
Python 2.4.3 (#1, Jan 14 2008, 18:32:40)
[GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def square(x):
... return x * x
...
>>> map(square, [1, 2, 3, 4])
[1, 4, 9, 16]
>>>
Installing
 Python is pre-installed on most Unix systems, including Linux
and MAC OS X
 The pre-installed version may not be the most recent one (2.6.2
and 3.1.1 as of Sept 09)
 Download from http://python.org/download/
 Latest version is 3.11.5
 Python comes with a large library of standard modules
 There are several options for an IDE
 IDLE – works well with Windows
 Emacs with python-mode or your favorite text editor
 Eclipse with Pydev (http://pydev.sourceforge.net/)
PyCharm
IDLE Development Environment
IDLE is an Integrated DeveLopment Environ-ment
for Python, typically used on Windows
Multi-window text editor with syntax highlighting,
auto-completion, smart indent and other.
Python shell with syntax highlighting.
Integrated debugger
with stepping, persis-
tent breakpoints,
and call stack visi-
bility
Running Interactively on UNIX
On Unix…
% python
>>> 3+3
6
 Python prompts with ‘>>>’.
 To exit Python (not Idle):
In Unix, type CONTROL-D
In Windows, type CONTROL-Z + <Enter>
Evaluate exit()
Running Programs on UNIX
 Call python program via the python interpreter
% python fact.py
 Make a python file directly executable by
 Adding the appropriate path to your python interpreter as
the first line of your file
#!/usr/bin/python
 Making the file executable
% chmod a+x fact.py
Invoking file from Unix command line
% fact.py
A Code Sample (in IDLE)
x = 34 - 23 # A comment.
y = “Hello” # Another one.
z = 3.45
if z == 3.45 or y == “Hello”:
x = x + 1
y = y + “ World” # String concat.
print (x)
print (y)
Enough to Understand the Code
 Indentation matters to code meaning
Block structure indicated by indentation
 First assignment to a variable creates it
Variable types don’t need to be declared.
Python figures out the variable types on its own.
 Assignment is = and comparison is ==
 For numbers + - * / % are as expected
Special use of + for string concatenation and % for string formatting (as in
C’s printf)
 Logical operators are words (and, or, not) not symbols
 The basic printing command is print
Basic Datatypes
 Integers (default for numbers)
z = 5 / 2 # Answer 2, integer division
 Floats
x = 3.456
 Strings
 Can use “” or ‘’ to specify with “abc” == ‘abc’
 Unmatched can occur within the string: “matt’s”
 Use triple double-quotes for multi-line strings or
strings than contain both ‘ and “ inside of them:
“““a‘b“c”””
Whitespace
Whitespace is meaningful in Python: especially indentation and
placement of newlines
Use a newline to end a line of code
Use  when must go to next line prematurely
No braces {} to mark blocks of code, use consistent indentation
instead
• First line with less indentation is outside of the block
• First line with more indentation starts a nested block
Colons start of a new block in many constructs, e.g. function
definitions, then clauses
Comments
Start comments with #, rest of line is ignored
Can include a “documentation string” as the first
line of a new function or class you define
Development environments, debugger, and other
tools use it: it’s good style to include one
def fact(n):
“““fact(n) assumes n is a positive
integer and returns facorial of n.”””
assert(n>0)
return 1 if n==1 else n*fact(n-1)

More Related Content

PPTX
Python_Introduction_Good_PPT.pptx
PDF
Pyhton-1a-Basics.pdf
PDF
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
PPTX
python PPT Session 1.pptx
PPTX
Introduction python
PPTX
Python Tutorial | Python Programming Language
PDF
Socket programming-in-python
PPTX
Python tutorial for beginners - Tib academy
Python_Introduction_Good_PPT.pptx
Pyhton-1a-Basics.pdf
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
python PPT Session 1.pptx
Introduction python
Python Tutorial | Python Programming Language
Socket programming-in-python
Python tutorial for beginners - Tib academy

Similar to Introduction to python.pptx (20)

PDF
intro.pptx (1).pdf
PPTX
Introduction to Python and Basic Syntax.pptx
PPTX
Python Programming | JNTUK | UNIT 1 | Lecture 3
PPTX
Introduction to python for Beginners
PPTX
UNIT 1 PYTHON introduction and basic level
PDF
Python and Pytorch tutorial and walkthrough
PDF
Python_final_print_vison_academy_9822506209.pdf
PPTX
python programminig and introduction.pptx
PPTX
Python Course Basic
PPT
Python for Engineers and Architects Stud
PDF
Introduction-to-Python-print-datatype.pdf
PPT
Cmpe202 01 Research
PPTX
Python Introduction
PPTX
unit (1)INTRODUCTION TO PYTHON course.pptx
PDF
Fundamentals of python
PPT
pythegggggeeeeeeeeeeeeeeeeeeeeeeeon1.ppt
PPT
uso del lenguaje de programación python en métodos numéricos..ppt
PPT
Learn Python in three hours - Python is an experiment
PPT
python1.pptpppppppppppppppppppppppppppppppp
PPT
python_presentation_for students_high_school
intro.pptx (1).pdf
Introduction to Python and Basic Syntax.pptx
Python Programming | JNTUK | UNIT 1 | Lecture 3
Introduction to python for Beginners
UNIT 1 PYTHON introduction and basic level
Python and Pytorch tutorial and walkthrough
Python_final_print_vison_academy_9822506209.pdf
python programminig and introduction.pptx
Python Course Basic
Python for Engineers and Architects Stud
Introduction-to-Python-print-datatype.pdf
Cmpe202 01 Research
Python Introduction
unit (1)INTRODUCTION TO PYTHON course.pptx
Fundamentals of python
pythegggggeeeeeeeeeeeeeeeeeeeeeeeon1.ppt
uso del lenguaje de programación python en métodos numéricos..ppt
Learn Python in three hours - Python is an experiment
python1.pptpppppppppppppppppppppppppppppppp
python_presentation_for students_high_school
Ad

Recently uploaded (20)

PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PPTX
Construction Project Organization Group 2.pptx
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
OOP with Java - Java Introduction (Basics)
PDF
737-MAX_SRG.pdf student reference guides
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
DOCX
573137875-Attendance-Management-System-original
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
composite construction of structures.pdf
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Sustainable Sites - Green Building Construction
Operating System & Kernel Study Guide-1 - converted.pdf
CH1 Production IntroductoryConcepts.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Construction Project Organization Group 2.pptx
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
CYBER-CRIMES AND SECURITY A guide to understanding
OOP with Java - Java Introduction (Basics)
737-MAX_SRG.pdf student reference guides
III.4.1.2_The_Space_Environment.p pdffdf
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
573137875-Attendance-Management-System-original
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Foundation to blockchain - A guide to Blockchain Tech
Automation-in-Manufacturing-Chapter-Introduction.pdf
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
composite construction of structures.pdf
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Sustainable Sites - Green Building Construction
Ad

Introduction to python.pptx

  • 3. Brief History of Python  Invented in the Netherlands, early 90s by Guido van Rossum(February 20, 1991)  Named after Monty Python  Open sourced from the beginning  Considered a scripting language, but is much more  Scalable, object oriented and functional from the beginning  Used by Google from the beginning  Increasingly popular
  • 4. Python Python is an open source, object - oriented, high- level powerful programming language. Developed by Guido Van Rossum in early 1990. Python is platform independent
  • 5. Introduction To Python Interpreter A python program is read by a parser. Python was designed to be highly readable language.
  • 6. Python Program Python program are composed of modules. Modules contain statements. Statements contain expressions. Expressions create and process objects.
  • 7. Features Of Python Open source Easy to learn
  • 8. Major Uses Of Python System utilities Web development Graphical user interface Internet scripting Embedded scripting
  • 9. Major Uses Of Python Database access and programm ing. Game programming Rapid prototyping and development Distributed programmin g
  • 10. Python Is Easy To Use C program C ++ program Java program Python program #include <stdio.h> int main (int argc,char ** argv) { Printf (“welcome”); } #include<iostream > int main() { Std:: cout <<“welcome”<<std::e ndl; return0; } Public class hello { Public static voidmain(string argv[]) { System .out. println(“welcom e”); } } Print (“welcome”)
  • 11. Python Definition Python is a high level programming language designed to be easy to read and simple to implement. Python is considered a scripting language. Scripts written in python (.py files ) can be parsed and run immediately.
  • 12. Python Coding Style Use 4 space per indentation and no tabs. Do not mix tabs and spaces. Maximum line length.
  • 13. Python Coding Style Use blank lines to separate top level function and class definitions. Inline comments (should be complete sentences). Use spaces around expression and statements.
  • 14. Python Is Interactive Python has an interactive console where you get a python prompt and interact with interpreter directly. • Interpreted • Extendable • Libraries • supports
  • 18. The Python Interpreter  Typical Python implementations offer both an interpreter and compiler  Interactive interface to Python with a read-eval-print loop [finin@linux2 ~]$ python Python 2.4.3 (#1, Jan 14 2008, 18:32:40) [GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def square(x): ... return x * x ... >>> map(square, [1, 2, 3, 4]) [1, 4, 9, 16] >>>
  • 19. Installing  Python is pre-installed on most Unix systems, including Linux and MAC OS X  The pre-installed version may not be the most recent one (2.6.2 and 3.1.1 as of Sept 09)  Download from http://python.org/download/  Latest version is 3.11.5  Python comes with a large library of standard modules  There are several options for an IDE  IDLE – works well with Windows  Emacs with python-mode or your favorite text editor  Eclipse with Pydev (http://pydev.sourceforge.net/) PyCharm
  • 20. IDLE Development Environment IDLE is an Integrated DeveLopment Environ-ment for Python, typically used on Windows Multi-window text editor with syntax highlighting, auto-completion, smart indent and other. Python shell with syntax highlighting. Integrated debugger with stepping, persis- tent breakpoints, and call stack visi- bility
  • 21. Running Interactively on UNIX On Unix… % python >>> 3+3 6  Python prompts with ‘>>>’.  To exit Python (not Idle): In Unix, type CONTROL-D In Windows, type CONTROL-Z + <Enter> Evaluate exit()
  • 22. Running Programs on UNIX  Call python program via the python interpreter % python fact.py  Make a python file directly executable by  Adding the appropriate path to your python interpreter as the first line of your file #!/usr/bin/python  Making the file executable % chmod a+x fact.py Invoking file from Unix command line % fact.py
  • 23. A Code Sample (in IDLE) x = 34 - 23 # A comment. y = “Hello” # Another one. z = 3.45 if z == 3.45 or y == “Hello”: x = x + 1 y = y + “ World” # String concat. print (x) print (y)
  • 24. Enough to Understand the Code  Indentation matters to code meaning Block structure indicated by indentation  First assignment to a variable creates it Variable types don’t need to be declared. Python figures out the variable types on its own.  Assignment is = and comparison is ==  For numbers + - * / % are as expected Special use of + for string concatenation and % for string formatting (as in C’s printf)  Logical operators are words (and, or, not) not symbols  The basic printing command is print
  • 25. Basic Datatypes  Integers (default for numbers) z = 5 / 2 # Answer 2, integer division  Floats x = 3.456  Strings  Can use “” or ‘’ to specify with “abc” == ‘abc’  Unmatched can occur within the string: “matt’s”  Use triple double-quotes for multi-line strings or strings than contain both ‘ and “ inside of them: “““a‘b“c”””
  • 26. Whitespace Whitespace is meaningful in Python: especially indentation and placement of newlines Use a newline to end a line of code Use when must go to next line prematurely No braces {} to mark blocks of code, use consistent indentation instead • First line with less indentation is outside of the block • First line with more indentation starts a nested block Colons start of a new block in many constructs, e.g. function definitions, then clauses
  • 27. Comments Start comments with #, rest of line is ignored Can include a “documentation string” as the first line of a new function or class you define Development environments, debugger, and other tools use it: it’s good style to include one def fact(n): “““fact(n) assumes n is a positive integer and returns facorial of n.””” assert(n>0) return 1 if n==1 else n*fact(n-1)