KEMBAR78
Introduction to Agile Software Development & Python | PPT
1
Introduction to
Agile Software Development
And
Python
By Tharindu Weerasinghe
BSc.Eng(Hons.), AMIESL
Software Engineer
Representing IFS R&D International | 2009
2
IFS-UoP Collaboration – Software Enginee
Later part of the Software Engineering course
conducted
for the
Computer Engineering Undergraduates
of the
Faculty of Engineering, University of Peradeniya.
3
What does the word ’Agile’ mean?
Moving quickly & lightly
4
What is meant by a Software Development Meth
A software development methodology or system development
methodology in software engineering is a framework that is used to structure,
plan, and control the process of developing an information system.
(Hope you know these things….)
5
So, What is meant by Agile Software
Development?
Agile software development is a group of software development methodologies
that are based on similar principles.
Agile methodologies generally promote,
 a project management process that encourages frequent inspection and
adaptation,
a leadership philosophy that encourages teamwork,
self-organization and accountability,
a set of engineering best practices that allow for rapid delivery of high-quality
software,
a business approach that aligns development with customer needs and company
goals.
6
The BIG picture of Agile Development….
7
So, Agile Development is not 100%
technical...?
•YES! The concepts behind Agile software development is not
purely based on technical aspects. It blends with technical,
management, personal aspects of a software developing team or
persons!
•Agile methods are a family of development processes, not a
single approach to software development.
•Initially, agile methods were called "lightweight methods." In
2001, prominent members of the community met at Snowbird,
Utah, and adopted the name "agile methods." Later, some of
these people formed The Agile Alliance, a non-profit organization
that promotes agile development.
8
Why Agile…?
Agile software enables you to build the right
software at the right time.
Agile is not about in-depth analysis and design that leads to a detailed
work breakdown structure that predicts on what day of the year eighteen
months in the future a team will deliver a certain set of features.
Agile is about continuous prioritization and customer review to insure
that meaningful features are delivered when they are ready and when
they are needed.
9
Agile(Adaptive) Vs Plan-Driven(Predictive):
Agile home ground: Plan-driven home ground:
Low criticality High criticality
Senior developers Junior developers
Requirements change very often Requirements don't change too often
Small number of developers Large number of developers
Culture that thrives on chaos Culture that demands order
10
Some features behind Agile Software
Development
Customer satisfaction by rapid, continuous delivery of useful software
Working software is delivered frequently (weeks rather than months)
Working software is the principal measure of progress
Even late changes in requirements are welcome
Close, daily cooperation between business people and developers
Face-to-face conversation is the best form of communication (Co-location)
Projects are built around motivated individuals, who should be trusted
Continuous attention to technical excellence and good design
Simplicity
Self-organizing teams
Regular adaptation to changing circumstances
11
Agile methods
Some of the well-known agile software development methods:
Agile Modeling
Agile Unified Process (AUP)
Agile Data Method
Crystal
Essential Unified Process (EssUP)
Extreme programming (XP)
Feature Driven Development (FDD)
Getting Real
Open Unified Process (OpenUP)
Scrum
12
Agile practices
Some of the well-known agile software development practices:
Test Driven Development (TDD)
Behavior Driven Development (BDD)
Continuous Integration
Pair Programming
Planning poker
13
Agile Languages
What’s an agile language?
An agile programming language is a language that helps to fulfill the agile values
and principles better than other languages, in the same sense as we think of agile
methods and agile modeling.
But can a language be agile?
YES! Why not? Well.., if a language can fulfill the concepts of agile software
development, then it can be called as an agile language.
Just like C++, Java, C#, .Net support Object Oriented concepts, languages that
can supports Agile concepts are called Agile Languages.
Note: Java and C# are NOT agile languages.
What are the examples?
Python, Perl, Ruby
We Will Learn some preliminary features of Python in this class…..
14
Features of Agile Languages
excellent for beginners, yet superb for experts
highly scalable, suitable for large projects as well as small ones
rapid development
portable, cross-platform
embeddable
easily extensible
object-oriented
you can get the job done
simple yet elegant
stable and mature
powerful standard libs
wealth of 3rd party packages
15
Agile Languages for Rapid
Prototyping
16
Software Prototyping
What are software prototypes?
Incomplete versions of the software program being developed.
e.g.: If you develop a simple software package for a customer for the first
time, you build a model of the product, which is NOT the final product; that is the
prototype)
What is software prototyping?
...of curse making the software prototypes…
Software prototyping is an activity during a certain software development, is the
creation of prototypes, i.e., incomplete versions of the software program being developed.
A prototype typically simulates only a few aspects of the features of the eventual
program, and may be completely different from the eventual implementation.
17
Software Prototyping
A prototype can be used in:
• The requirements engineering process to help with requirements elicitation &
validation.
• In design processes to explore options and develop a UI design.
• In the testing process to run back-to-back tests.
Prototyping Process:
18
Software Prototyping
Advantages of Prototyping
Reduced time and costs
Improved and increased user involvement
Improved system usability
A closer match to users’ real needs
Improved design quality
Improved maintainability
Disadvantages of Prototyping
Insufficient analysis
User confusion of prototype and finished system
Developer misunderstanding of user objectives
Developer attachment to prototype
Excessive development time of the prototype
Expense of implementing prototyping
19
Software Prototyping
Categories of Prototyping
Software prototyping has many variants. However, all the methods are in
some way based on two major types of prototyping:
 Evolutionary Prototyping
 Throwaway(Rapid) Prototyping
This lecture series focus on Rapid Prototyping (Throwaway) But before we
go into Rapid Prototyping in detail, let me brief you both of them.
20
Evolutionary prototyping
Build prototype
system
Develop abstract
specification
Use prototype
system
Deliver
system
System
adequate?
YES
N
21
Throwaway(Rapid) prototyping
Outline
requirements
Develop
prototype
Evaluate
prototype
Specify
system
Develop
software
Validate
system
Delivered
software
system
Reusable
components
22
Rapid prototyping (Further…)
Rapid prototyping techniques:
Various techniques may be used for rapid development.
Dynamic high-level language development
Database programming
Component and application assembly
These techniques are often used together.
Visual programming is an inherent part of most prototype development
systems.
23
Rapid prototyping (Further…)
Rapid prototyping RISKS…
Mistaken concepts of rapid prototyping concerning definitions, objectives and correct
application of the technique.
Disagreements with users and customers regarding methodology, standards, tools and so
on.
Out-of-control users who want to iterate and evolve a prototype into a system that does
everything for everyone all of the time
Budget slashes and effort shortcuts - temptations brought about by use of the word ‘rapid’
Premature delivery of a prototype instead of a final (thoroughly documented and tuned)
product
Over-evolved prototypes - substituting elegance and efficiency for flexibility
24
Python for Rapid Prototyping
Python is an agile language which supports Agile Methodologies. Agile
methodologies helps Rapid Prototyping a lot!
A Japanese Software Engineer KOICHI TAMURA says in his blog:-
“As you know in a project where multiple people are working on, it's quite common that there are
tasks that can be done only after some other tasks is completed, and if you have made a schedule you'll
know for that reason it's difficult to make a schedule. At the last project I often used Python for rapid
prototyping to complete a task to make the team working efficiently, not making a member bored by just
waiting for his workmate finish a task. We could rewrite the script in c++ for better performance later when
there was enough time. If we had been coding only in c++, the project might have been ended up in failure.
Python worked so nice.”
25
Shall we learn Python Basics?
What is Python...?
Python is a dynamic object-oriented programming language that can be
used for many kinds of software development.
It offers strong support for integration with other languages and tools,
comes with extensive standard libraries, and can be learned in a few days.
Many Python programmers report substantial productivity gains and feel
the language encourages the development of higher quality, more
maintainable code.
Python's core syntax and semantics are minimalistic, while the standard library
is large and comprehensive. Its use of whitespace as block delimiters is unusual
among popular programming languages.
26
Little bit from History…
Python was conceived in the late 1980s by Guido van Rossum at CWI [National Research Institute
for Mathematics and Computer Science (Dutch: Centrum voor Wiskunde en Informatica or CWI)]
in the Netherlands as a successor to the ABC programming language (itself inspired by SETL- a high-
level programming language) capable of exception handling and interfacing with the Amoeba
operating system.
Van Rossum is Python's principal author, and his continuing central role in deciding the direction
of Python is reflected in the title given to him by the Python community, Benevolent Dictator for Life
(BDFL).
Python 2.0 was released on 16 October 2000, with many major new features including a full
garbage collector and support for Unicode. However, the most important change was to the
development process itself, with a shift to a more transparent and community-backed process.
Python 3.0, a major, backwards-incompatible release, was released on 3 December 2008 after a
long period of testing. Many of its major features have been back ported to the backwards-
compatible Python 2.6.
27
Python Applications used in..,
Web and Internet Development
Database Access
Desktop GUIs
Scientific and Numeric
Education
Network Programming
Software Development
Game and 3D Graphics
28
Learn PYTHON........
29
Shall we learn some syntaxes via simple examples
I will give some sample codes to show you the syntaxes of Python Coding.
We can use Python 3.0 in Windows environment which has a good GUI (IDE)
as well. So it is easy to code…
In the following examples, input and output are distinguished by the
presence or absence of prompts (>>> and ...): to repeat the example, you
must type everything after the prompt, when the prompt appears; lines that do
not begin with a prompt are output from the interpreter. Note that a secondary
prompt on a line by itself in an example means you must type a blank line; this
is used to end a multi-line command.
30
Shall we learn some syntaxes via simple examples
Comments in Python:
Start with the hash character, #, and extend to the end of the physical
line. A comment may appear at the start of a line or following whitespace or
code, but not within a string literal. A hash character within a string literal is
just a hash character. Since comments are to clarify code and are not
interpreted by Python, they may be omitted when typing in examples.
Some examples:
# this is the first comment
SPAM = 1 # and this is the second comment
# ... and now a third!
STRING = "# This is not a comment."
31
Shall we learn some syntaxes via simple examples
Using Python as a Calculator:
Let’s try some simple Python commands. Start the interpreter and wait for the primary prompt, >>>. (It shouldn’t take
long.)
Numbers:
The interpreter acts as a simple calculator: you can type an expression at it and it will write the value. Expression syntax is
straightforward: the operators +, -, * and / work just like in most other languages (for example, Pascal or C); parentheses can be used
for grouping. For example:
>>> 2+2
4
>>> # This is a comment
... 2+2
4
>>> 2+2 # and a comment on the same line as code
4
>>> (50-5*6)/4
5
>>> # Integer division returns the floor:
... 7/3
2
>>> 7/-3
-3
32
Shall we learn some syntaxes via simple examples
The equal sign ('=') is used to assign a value to a variable.
Afterwards, no result is displayed before the next interactive prompt:
>>> width = 10
>>> height = 5*4
>>> width * height
200
A value can be assigned to several variables simultaneously:
>>> x = y = z = 0 # Zero x, y and z
>>> x
0
>>> y
0
>>> z
0
33
Shall we learn some syntaxes via simple examples
Variables must be “defined” (assigned a value) before they can be used,
or an error will occur:
>>> # try to access an undefined variable
... n
This is the error Message you get:-
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
NameError: name 'n' is not defined
There is full support for floating point;
operators with mixed type operands convert the integer operand to floating point:
>>> 3 * 3.75 / 1.5
7.5
>>> 7.0 / 2
3.5
34
Shall we learn some syntaxes via simple examples
Complex numbers are also supported;
Imaginary numbers are written with a suffix of j or J.
Complex numbers with a nonzero real component are written as (real+imagj), or can be created with the
complex(real, imag) function.
>>> 1j * 1J
(-1+0j)  This is the output you get
>>> 1j * complex(0,1)
(-1+0j)  This is the output you get
>>> 3+1j*3
(3+3j)  This is the output you get
>>> (3+1j)*3
(9+3j)  This is the output you get
>>> (1+2j)/(1+1j)
(1.5+0.5j)  This is the output you get
35
Shall we learn some syntaxes via simple examples
Complex numbers are always represented as two floating point numbers, the real and imaginary part. To
extract these parts from a complex number z, use z.real and z.imag.
>>> a=1.5+0.5j
>>> a.real
1.5  This is the output you get
>>> a.imag
0.5  This is the output you get
The conversion functions to floating point and integer (float(), int() and long()) don’t work for complex
numbers — there is no one correct way to convert a complex number to a real number. Use abs(z) to get its
magnitude (as a float) or z.real to get its real part.
>>> a.real
3.0
>>> a.imag
4.0
>>> abs(a) # sqrt(a.real**2 + a.imag**2)
5.0
36
Shall we learn some syntaxes via simple examples
Strings:
Besides numbers, Python can also manipulate strings, which can be expressed in several ways. They can
be enclosed in single quotes or double quotes:
>>> 'spam eggs'
'spam eggs'  This is the output you get
>>> 'doesn't'
"doesn't"  This is the output you get
>>> "doesn't"
"doesn't"  This is the output you get
>>> '"Yes," he said.'
'"Yes," he said.'  This is the output you get
>>> ""Yes," he said."
'"Yes," he said.'  This is the output you get
>>> '"Isn't," she said.'
'"Isn't," she said.'  This is the output you get
37
Shall we learn some syntaxes via simple examples
String literals can span multiple lines in several ways. Continuation lines can be used, with a
backslash as the last character on the line indicating that the next line is a logical continuation of the
line:
>>>hello = "This is a rather long string containingnseveral
lines of text just as you would do in C.nNote that whitespace at
the beginning of the line is significant.“
Note that newlines still need to be embedded in the string using n; the newline following the
trailing backslash is discarded. This example would print the following:
This is a rather long string containing
several lines of text just as you would do in C.
Note that whitespace at the beginning of the line is
significant.
38
Shall we learn some syntaxes via simple examples
Strings can be concatenated (glued together) with the + operator, and repeated with *:
>>> word = 'Help' + 'A'
>>> word 'HelpA'
>>> '<' + word*5 + '>'
'<HelpAHelpAHelpAHelpAHelpA>‘
Two string literals next to each other are automatically concatenated; the first line above could also have
been written word = 'Help' 'A'; this only works with two literals, not with arbitrary string expressions:
>>> 'str' 'ing' # <- This is ok
'string'
>>> 'str'.strip() + 'ing' # <- This is ok
'string'
>>> 'str'.strip() 'ing' # <- This is invalid File
"<stdin>", line 1, in ? 'str'.strip() 'ing' ^
SyntaxError: invalid syntax
39
Shall we learn some syntaxes via simple examples
Input & Output:
>>> s = 'Hello, world.’
>>> str(s)
‘Hello, world.’  This is the output you get
>>> repr(s)
“‘Hello, world.’”  This is the output you get
>>> str(0.1)
‘0.1’  This is the output you get
>>> repr(0.1)
‘0.10000000000000001’  This is the output you get
40
Shall we learn some syntaxes via simple examples
>>> x = 10 * 3.25
>>> y = 200 * 200
>>> s = 'The value of x is ' + repr(x) + ', and y is ' + repr(y) + '... '
>>> s
The value of x is 32.5, and y is 40000...  This is the output you
get
>>> # The repr() of a string adds string quotes and backslashes:...
>>> hello = 'hello, worldn‘
>>> hellos = repr(hello)
>>> hellos
‘hello, worldn’  This is the output you get
>>> # The argument to repr() may be any Python object:
... repr((x, y, ('spam', 'eggs')))
"(32.5, 40000, ('spam', 'eggs'))"  This is the output you get
That’s it from me…You can learn Python by trying it out by your self!
Wish you all the best for your future!
THANK YOU!
Special mention:
All on-line material referred when preparing these slides.
© 2009 IFS

Introduction to Agile Software Development & Python

  • 1.
    1 Introduction to Agile SoftwareDevelopment And Python By Tharindu Weerasinghe BSc.Eng(Hons.), AMIESL Software Engineer Representing IFS R&D International | 2009
  • 2.
    2 IFS-UoP Collaboration –Software Enginee Later part of the Software Engineering course conducted for the Computer Engineering Undergraduates of the Faculty of Engineering, University of Peradeniya.
  • 3.
    3 What does theword ’Agile’ mean? Moving quickly & lightly
  • 4.
    4 What is meantby a Software Development Meth A software development methodology or system development methodology in software engineering is a framework that is used to structure, plan, and control the process of developing an information system. (Hope you know these things….)
  • 5.
    5 So, What ismeant by Agile Software Development? Agile software development is a group of software development methodologies that are based on similar principles. Agile methodologies generally promote,  a project management process that encourages frequent inspection and adaptation, a leadership philosophy that encourages teamwork, self-organization and accountability, a set of engineering best practices that allow for rapid delivery of high-quality software, a business approach that aligns development with customer needs and company goals.
  • 6.
    6 The BIG pictureof Agile Development….
  • 7.
    7 So, Agile Developmentis not 100% technical...? •YES! The concepts behind Agile software development is not purely based on technical aspects. It blends with technical, management, personal aspects of a software developing team or persons! •Agile methods are a family of development processes, not a single approach to software development. •Initially, agile methods were called "lightweight methods." In 2001, prominent members of the community met at Snowbird, Utah, and adopted the name "agile methods." Later, some of these people formed The Agile Alliance, a non-profit organization that promotes agile development.
  • 8.
    8 Why Agile…? Agile softwareenables you to build the right software at the right time. Agile is not about in-depth analysis and design that leads to a detailed work breakdown structure that predicts on what day of the year eighteen months in the future a team will deliver a certain set of features. Agile is about continuous prioritization and customer review to insure that meaningful features are delivered when they are ready and when they are needed.
  • 9.
    9 Agile(Adaptive) Vs Plan-Driven(Predictive): Agilehome ground: Plan-driven home ground: Low criticality High criticality Senior developers Junior developers Requirements change very often Requirements don't change too often Small number of developers Large number of developers Culture that thrives on chaos Culture that demands order
  • 10.
    10 Some features behindAgile Software Development Customer satisfaction by rapid, continuous delivery of useful software Working software is delivered frequently (weeks rather than months) Working software is the principal measure of progress Even late changes in requirements are welcome Close, daily cooperation between business people and developers Face-to-face conversation is the best form of communication (Co-location) Projects are built around motivated individuals, who should be trusted Continuous attention to technical excellence and good design Simplicity Self-organizing teams Regular adaptation to changing circumstances
  • 11.
    11 Agile methods Some ofthe well-known agile software development methods: Agile Modeling Agile Unified Process (AUP) Agile Data Method Crystal Essential Unified Process (EssUP) Extreme programming (XP) Feature Driven Development (FDD) Getting Real Open Unified Process (OpenUP) Scrum
  • 12.
    12 Agile practices Some ofthe well-known agile software development practices: Test Driven Development (TDD) Behavior Driven Development (BDD) Continuous Integration Pair Programming Planning poker
  • 13.
    13 Agile Languages What’s anagile language? An agile programming language is a language that helps to fulfill the agile values and principles better than other languages, in the same sense as we think of agile methods and agile modeling. But can a language be agile? YES! Why not? Well.., if a language can fulfill the concepts of agile software development, then it can be called as an agile language. Just like C++, Java, C#, .Net support Object Oriented concepts, languages that can supports Agile concepts are called Agile Languages. Note: Java and C# are NOT agile languages. What are the examples? Python, Perl, Ruby We Will Learn some preliminary features of Python in this class…..
  • 14.
    14 Features of AgileLanguages excellent for beginners, yet superb for experts highly scalable, suitable for large projects as well as small ones rapid development portable, cross-platform embeddable easily extensible object-oriented you can get the job done simple yet elegant stable and mature powerful standard libs wealth of 3rd party packages
  • 15.
    15 Agile Languages forRapid Prototyping
  • 16.
    16 Software Prototyping What aresoftware prototypes? Incomplete versions of the software program being developed. e.g.: If you develop a simple software package for a customer for the first time, you build a model of the product, which is NOT the final product; that is the prototype) What is software prototyping? ...of curse making the software prototypes… Software prototyping is an activity during a certain software development, is the creation of prototypes, i.e., incomplete versions of the software program being developed. A prototype typically simulates only a few aspects of the features of the eventual program, and may be completely different from the eventual implementation.
  • 17.
    17 Software Prototyping A prototypecan be used in: • The requirements engineering process to help with requirements elicitation & validation. • In design processes to explore options and develop a UI design. • In the testing process to run back-to-back tests. Prototyping Process:
  • 18.
    18 Software Prototyping Advantages ofPrototyping Reduced time and costs Improved and increased user involvement Improved system usability A closer match to users’ real needs Improved design quality Improved maintainability Disadvantages of Prototyping Insufficient analysis User confusion of prototype and finished system Developer misunderstanding of user objectives Developer attachment to prototype Excessive development time of the prototype Expense of implementing prototyping
  • 19.
    19 Software Prototyping Categories ofPrototyping Software prototyping has many variants. However, all the methods are in some way based on two major types of prototyping:  Evolutionary Prototyping  Throwaway(Rapid) Prototyping This lecture series focus on Rapid Prototyping (Throwaway) But before we go into Rapid Prototyping in detail, let me brief you both of them.
  • 20.
    20 Evolutionary prototyping Build prototype system Developabstract specification Use prototype system Deliver system System adequate? YES N
  • 21.
  • 22.
    22 Rapid prototyping (Further…) Rapidprototyping techniques: Various techniques may be used for rapid development. Dynamic high-level language development Database programming Component and application assembly These techniques are often used together. Visual programming is an inherent part of most prototype development systems.
  • 23.
    23 Rapid prototyping (Further…) Rapidprototyping RISKS… Mistaken concepts of rapid prototyping concerning definitions, objectives and correct application of the technique. Disagreements with users and customers regarding methodology, standards, tools and so on. Out-of-control users who want to iterate and evolve a prototype into a system that does everything for everyone all of the time Budget slashes and effort shortcuts - temptations brought about by use of the word ‘rapid’ Premature delivery of a prototype instead of a final (thoroughly documented and tuned) product Over-evolved prototypes - substituting elegance and efficiency for flexibility
  • 24.
    24 Python for RapidPrototyping Python is an agile language which supports Agile Methodologies. Agile methodologies helps Rapid Prototyping a lot! A Japanese Software Engineer KOICHI TAMURA says in his blog:- “As you know in a project where multiple people are working on, it's quite common that there are tasks that can be done only after some other tasks is completed, and if you have made a schedule you'll know for that reason it's difficult to make a schedule. At the last project I often used Python for rapid prototyping to complete a task to make the team working efficiently, not making a member bored by just waiting for his workmate finish a task. We could rewrite the script in c++ for better performance later when there was enough time. If we had been coding only in c++, the project might have been ended up in failure. Python worked so nice.”
  • 25.
    25 Shall we learnPython Basics? What is Python...? Python is a dynamic object-oriented programming language that can be used for many kinds of software development. It offers strong support for integration with other languages and tools, comes with extensive standard libraries, and can be learned in a few days. Many Python programmers report substantial productivity gains and feel the language encourages the development of higher quality, more maintainable code. Python's core syntax and semantics are minimalistic, while the standard library is large and comprehensive. Its use of whitespace as block delimiters is unusual among popular programming languages.
  • 26.
    26 Little bit fromHistory… Python was conceived in the late 1980s by Guido van Rossum at CWI [National Research Institute for Mathematics and Computer Science (Dutch: Centrum voor Wiskunde en Informatica or CWI)] in the Netherlands as a successor to the ABC programming language (itself inspired by SETL- a high- level programming language) capable of exception handling and interfacing with the Amoeba operating system. Van Rossum is Python's principal author, and his continuing central role in deciding the direction of Python is reflected in the title given to him by the Python community, Benevolent Dictator for Life (BDFL). Python 2.0 was released on 16 October 2000, with many major new features including a full garbage collector and support for Unicode. However, the most important change was to the development process itself, with a shift to a more transparent and community-backed process. Python 3.0, a major, backwards-incompatible release, was released on 3 December 2008 after a long period of testing. Many of its major features have been back ported to the backwards- compatible Python 2.6.
  • 27.
    27 Python Applications usedin.., Web and Internet Development Database Access Desktop GUIs Scientific and Numeric Education Network Programming Software Development Game and 3D Graphics
  • 28.
  • 29.
    29 Shall we learnsome syntaxes via simple examples I will give some sample codes to show you the syntaxes of Python Coding. We can use Python 3.0 in Windows environment which has a good GUI (IDE) as well. So it is easy to code… In the following examples, input and output are distinguished by the presence or absence of prompts (>>> and ...): to repeat the example, you must type everything after the prompt, when the prompt appears; lines that do not begin with a prompt are output from the interpreter. Note that a secondary prompt on a line by itself in an example means you must type a blank line; this is used to end a multi-line command.
  • 30.
    30 Shall we learnsome syntaxes via simple examples Comments in Python: Start with the hash character, #, and extend to the end of the physical line. A comment may appear at the start of a line or following whitespace or code, but not within a string literal. A hash character within a string literal is just a hash character. Since comments are to clarify code and are not interpreted by Python, they may be omitted when typing in examples. Some examples: # this is the first comment SPAM = 1 # and this is the second comment # ... and now a third! STRING = "# This is not a comment."
  • 31.
    31 Shall we learnsome syntaxes via simple examples Using Python as a Calculator: Let’s try some simple Python commands. Start the interpreter and wait for the primary prompt, >>>. (It shouldn’t take long.) Numbers: The interpreter acts as a simple calculator: you can type an expression at it and it will write the value. Expression syntax is straightforward: the operators +, -, * and / work just like in most other languages (for example, Pascal or C); parentheses can be used for grouping. For example: >>> 2+2 4 >>> # This is a comment ... 2+2 4 >>> 2+2 # and a comment on the same line as code 4 >>> (50-5*6)/4 5 >>> # Integer division returns the floor: ... 7/3 2 >>> 7/-3 -3
  • 32.
    32 Shall we learnsome syntaxes via simple examples The equal sign ('=') is used to assign a value to a variable. Afterwards, no result is displayed before the next interactive prompt: >>> width = 10 >>> height = 5*4 >>> width * height 200 A value can be assigned to several variables simultaneously: >>> x = y = z = 0 # Zero x, y and z >>> x 0 >>> y 0 >>> z 0
  • 33.
    33 Shall we learnsome syntaxes via simple examples Variables must be “defined” (assigned a value) before they can be used, or an error will occur: >>> # try to access an undefined variable ... n This is the error Message you get:- Traceback (most recent call last): File “<stdin>”, line 1, in <module> NameError: name 'n' is not defined There is full support for floating point; operators with mixed type operands convert the integer operand to floating point: >>> 3 * 3.75 / 1.5 7.5 >>> 7.0 / 2 3.5
  • 34.
    34 Shall we learnsome syntaxes via simple examples Complex numbers are also supported; Imaginary numbers are written with a suffix of j or J. Complex numbers with a nonzero real component are written as (real+imagj), or can be created with the complex(real, imag) function. >>> 1j * 1J (-1+0j)  This is the output you get >>> 1j * complex(0,1) (-1+0j)  This is the output you get >>> 3+1j*3 (3+3j)  This is the output you get >>> (3+1j)*3 (9+3j)  This is the output you get >>> (1+2j)/(1+1j) (1.5+0.5j)  This is the output you get
  • 35.
    35 Shall we learnsome syntaxes via simple examples Complex numbers are always represented as two floating point numbers, the real and imaginary part. To extract these parts from a complex number z, use z.real and z.imag. >>> a=1.5+0.5j >>> a.real 1.5  This is the output you get >>> a.imag 0.5  This is the output you get The conversion functions to floating point and integer (float(), int() and long()) don’t work for complex numbers — there is no one correct way to convert a complex number to a real number. Use abs(z) to get its magnitude (as a float) or z.real to get its real part. >>> a.real 3.0 >>> a.imag 4.0 >>> abs(a) # sqrt(a.real**2 + a.imag**2) 5.0
  • 36.
    36 Shall we learnsome syntaxes via simple examples Strings: Besides numbers, Python can also manipulate strings, which can be expressed in several ways. They can be enclosed in single quotes or double quotes: >>> 'spam eggs' 'spam eggs'  This is the output you get >>> 'doesn't' "doesn't"  This is the output you get >>> "doesn't" "doesn't"  This is the output you get >>> '"Yes," he said.' '"Yes," he said.'  This is the output you get >>> ""Yes," he said." '"Yes," he said.'  This is the output you get >>> '"Isn't," she said.' '"Isn't," she said.'  This is the output you get
  • 37.
    37 Shall we learnsome syntaxes via simple examples String literals can span multiple lines in several ways. Continuation lines can be used, with a backslash as the last character on the line indicating that the next line is a logical continuation of the line: >>>hello = "This is a rather long string containingnseveral lines of text just as you would do in C.nNote that whitespace at the beginning of the line is significant.“ Note that newlines still need to be embedded in the string using n; the newline following the trailing backslash is discarded. This example would print the following: This is a rather long string containing several lines of text just as you would do in C. Note that whitespace at the beginning of the line is significant.
  • 38.
    38 Shall we learnsome syntaxes via simple examples Strings can be concatenated (glued together) with the + operator, and repeated with *: >>> word = 'Help' + 'A' >>> word 'HelpA' >>> '<' + word*5 + '>' '<HelpAHelpAHelpAHelpAHelpA>‘ Two string literals next to each other are automatically concatenated; the first line above could also have been written word = 'Help' 'A'; this only works with two literals, not with arbitrary string expressions: >>> 'str' 'ing' # <- This is ok 'string' >>> 'str'.strip() + 'ing' # <- This is ok 'string' >>> 'str'.strip() 'ing' # <- This is invalid File "<stdin>", line 1, in ? 'str'.strip() 'ing' ^ SyntaxError: invalid syntax
  • 39.
    39 Shall we learnsome syntaxes via simple examples Input & Output: >>> s = 'Hello, world.’ >>> str(s) ‘Hello, world.’  This is the output you get >>> repr(s) “‘Hello, world.’”  This is the output you get >>> str(0.1) ‘0.1’  This is the output you get >>> repr(0.1) ‘0.10000000000000001’  This is the output you get
  • 40.
    40 Shall we learnsome syntaxes via simple examples >>> x = 10 * 3.25 >>> y = 200 * 200 >>> s = 'The value of x is ' + repr(x) + ', and y is ' + repr(y) + '... ' >>> s The value of x is 32.5, and y is 40000...  This is the output you get >>> # The repr() of a string adds string quotes and backslashes:... >>> hello = 'hello, worldn‘ >>> hellos = repr(hello) >>> hellos ‘hello, worldn’  This is the output you get >>> # The argument to repr() may be any Python object: ... repr((x, y, ('spam', 'eggs'))) "(32.5, 40000, ('spam', 'eggs'))"  This is the output you get
  • 41.
    That’s it fromme…You can learn Python by trying it out by your self! Wish you all the best for your future! THANK YOU!
  • 42.
    Special mention: All on-linematerial referred when preparing these slides. © 2009 IFS

Editor's Notes

  • #2 1
  • #4 3
  • #6 5
  • #8 7
  • #11 10
  • #16 15
  • #21 Evolutionary prototyping: An initial prototype is produced and refined through a number of stages to the final system The objective of evolutionary prototyping is to deliver a working system to end-users: The development starts with those requirements which are best understood. Must be used for systems where the specification cannot be developed in advance. E.g., AI systems and user interface systems Based on techniques which allow rapid system iterations. Verification is impossible as there is no specification. Validation means demonstrating the adequacy of the system. Evolutionary prototyping advantages: * Accelerated delivery of the system: Rapid delivery and deployment are sometimes more important than functionality or long-term software maintainability. * User engagement with the system: Not only is the system more likely to meet user requirements, they are more likely to commit to the use of the system.
  • #22 Used to reduce requirements risk. The prototype is developed from an initial specification, delivered for experiment then discarded. The throw-away prototype should NOT be considered as a final system Some system characteristics may have been left out There is no specification for long-term maintenance The system will be poorly structured and difficult to maintain Various techniques may be used for rapid development Dynamic high-level language development Database programming Component and application assembly These techniques are often used together Visual programming is an inherent part of most prototype development systems
  • #23 Used to reduce requirements risk. The prototype is developed from an initial specification, delivered for experiment then discarded. The throw-away prototype should NOT be considered as a final system Some system characteristics may have been left out There is no specification for long-term maintenance The system will be poorly structured and difficult to maintain Various techniques may be used for rapid development Dynamic high-level language development Database programming Component and application assembly These techniques are often used together Visual programming is an inherent part of most prototype development systems
  • #24 Used to reduce requirements risk. The prototype is developed from an initial specification, delivered for experiment then discarded. The throw-away prototype should NOT be considered as a final system Some system characteristics may have been left out There is no specification for long-term maintenance The system will be poorly structured and difficult to maintain Various techniques may be used for rapid development Dynamic high-level language development Database programming Component and application assembly These techniques are often used together Visual programming is an inherent part of most prototype development systems