This document provides an introduction to the Python programming language. It discusses that Python is an open source, high-level, dynamic typed language with a standard distribution of modules. It can be compiled or run just-in-time and interfaces with COM and open source GIS toolsets. The document then discusses why Python is preferable to other languages for GIS tasks and provides overviews of Python interfaces like IDLE and modules. It provides examples of basic Python code and discusses objects, strings, lists, tuples, dictionaries, conditionals, loops, files and error handling in Python.
python programming language Python is a high-level, interpreted, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation. INTRODUCTION
HISTORY
USES OF PYTHON
FEATURES OF PYTHON
PYTHON PROJECT FOR BEGINNERS
PYTHON PROGRAM
KEY CHANGES IN PYTHON
BASIC SYNTAX
VARIABLE
NUMBERS
STANDARD TYPE HIERARCHY
STRING
CONDITIONALS
FOR LOOP
FUNCTION
KEYWORDS
WHY PYTHON ?
DIFFERENTIATE
EXAMPLES
The document provides information about a course on Object Oriented Programming concepts in Python. It outlines 6 course outcomes related to illustrating Python basics, developing scripts using control statements and data types, constructing object oriented programs using functions, and applying concepts like inheritance, polymorphism, and exception handling. It also mentions the syllabus, books and references, and provides introductory information about Python including its history, uses, installation process, interpreted nature, and basic programming concepts.
The document provides information on various testing concepts like regression testing, manual testing, automation testing, and the differences between manual and automation testing. It discusses topics like processing time, exploratory testing, initial investment, reliability, handling UI changes, required resources, value for money, performance testing, programming knowledge requirements, use in DevOps, and ideal use cases for each method. Automation testing is summarized as bringing efficiency while manual testing is still needed in some cases.
Python is an interpreted, object-oriented programming language that uses indentation to identify blocks of code. It is dynamically typed and strongly typed, with objects determining types at runtime rather than requiring explicit type declaration. Common data types include mutable types like lists and dictionaries as well as immutable types like strings and tuples.
The document summarizes the internship training that Shivam Denge completed from July 5th to August 16th 2022 at iBase Technology. The 6-week online training covered topics like Python programming language features, variables, loops, data structures, Numpy, Tkinter, Turtle and MySQL database modules. Key aspects of Python like being an interpreted, object-oriented and cross-platform language were also highlighted.
The document discusses Python interview questions and answers related to Python fundamentals like data types, variables, functions, objects and classes. Some key points include:
- Python is an interpreted, interactive and object-oriented programming language. It uses indentation to identify code blocks rather than brackets.
- Python supports dynamic typing where the type is determined at runtime. It is strongly typed meaning operations inappropriate for a type will fail with an exception.
- Common data types include lists (mutable), tuples (immutable), dictionaries, strings and numbers.
- Functions use def, parameters are passed by reference, and variables can be local or global scope.
- Classes use inheritance, polymorphism and encapsulation to create
The document provides an overview of the Python programming language, its applications, and key concepts. It discusses how Python is a versatile, high-level language suitable for web development, data science, scripting, scientific computing, and more. The document then covers Python's syntax, data types, operators, functions, modules, file handling capabilities, and compares Python to other languages like Java and C. It also provides examples of common Python programming concepts like lists, dictionaries, functions, classes and exceptions.
The document describes an internship training in Python conducted over 6 weeks. It provides an introduction to Python, describing it as a general purpose programming language that can be used for various applications. It then discusses key Python features and concepts like variables, loops, data structures, modules like NumPy, Tkinter, Turtle and how to connect Python to MySQL databases. Code examples are provided to demonstrate basic usage of these features and modules.
python programming language Python is a high-level, interpreted, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation. INTRODUCTION
HISTORY
USES OF PYTHON
FEATURES OF PYTHON
PYTHON PROJECT FOR BEGINNERS
PYTHON PROGRAM
KEY CHANGES IN PYTHON
BASIC SYNTAX
VARIABLE
NUMBERS
STANDARD TYPE HIERARCHY
STRING
CONDITIONALS
FOR LOOP
FUNCTION
KEYWORDS
WHY PYTHON ?
DIFFERENTIATE
EXAMPLES
The document provides information about a course on Object Oriented Programming concepts in Python. It outlines 6 course outcomes related to illustrating Python basics, developing scripts using control statements and data types, constructing object oriented programs using functions, and applying concepts like inheritance, polymorphism, and exception handling. It also mentions the syllabus, books and references, and provides introductory information about Python including its history, uses, installation process, interpreted nature, and basic programming concepts.
The document provides information on various testing concepts like regression testing, manual testing, automation testing, and the differences between manual and automation testing. It discusses topics like processing time, exploratory testing, initial investment, reliability, handling UI changes, required resources, value for money, performance testing, programming knowledge requirements, use in DevOps, and ideal use cases for each method. Automation testing is summarized as bringing efficiency while manual testing is still needed in some cases.
Python is an interpreted, object-oriented programming language that uses indentation to identify blocks of code. It is dynamically typed and strongly typed, with objects determining types at runtime rather than requiring explicit type declaration. Common data types include mutable types like lists and dictionaries as well as immutable types like strings and tuples.
The document summarizes the internship training that Shivam Denge completed from July 5th to August 16th 2022 at iBase Technology. The 6-week online training covered topics like Python programming language features, variables, loops, data structures, Numpy, Tkinter, Turtle and MySQL database modules. Key aspects of Python like being an interpreted, object-oriented and cross-platform language were also highlighted.
The document discusses Python interview questions and answers related to Python fundamentals like data types, variables, functions, objects and classes. Some key points include:
- Python is an interpreted, interactive and object-oriented programming language. It uses indentation to identify code blocks rather than brackets.
- Python supports dynamic typing where the type is determined at runtime. It is strongly typed meaning operations inappropriate for a type will fail with an exception.
- Common data types include lists (mutable), tuples (immutable), dictionaries, strings and numbers.
- Functions use def, parameters are passed by reference, and variables can be local or global scope.
- Classes use inheritance, polymorphism and encapsulation to create
The document provides an overview of the Python programming language, its applications, and key concepts. It discusses how Python is a versatile, high-level language suitable for web development, data science, scripting, scientific computing, and more. The document then covers Python's syntax, data types, operators, functions, modules, file handling capabilities, and compares Python to other languages like Java and C. It also provides examples of common Python programming concepts like lists, dictionaries, functions, classes and exceptions.
The document describes an internship training in Python conducted over 6 weeks. It provides an introduction to Python, describing it as a general purpose programming language that can be used for various applications. It then discusses key Python features and concepts like variables, loops, data structures, modules like NumPy, Tkinter, Turtle and how to connect Python to MySQL databases. Code examples are provided to demonstrate basic usage of these features and modules.
This document provides an introduction to Python programming through a series of lectures. It begins with defining Python, what it can be used for, and why it is a popular language. It then covers Python syntax compared to other languages, getting started with Python including installation and running a simple program. The document continues with topics like Python variables, data types, strings, numbers, operators, and lists. It provides examples and explanations of core Python concepts to help newcomers learn the essentials of the language.
The document provides information about various Python concepts like PEP 8, pickling, lambda functions, generators, modules, packages and more. It also includes questions about memory management in Python, tools for static analysis, decorators, iterators, slicing, and other common Python interview questions.
This document provides an overview of Python programming in Katana for beginners. It discusses scripting languages and their advantages, different programming paradigms like procedural and object-oriented programming, and key Python concepts like data types, variables, functions, modules and packages. The document also demonstrates how to get started with Python in Katana, covering topics like syntax, comments, writing scripts and using the interactive console.
This file contains the first steps any beginner can take as he/she starts a journey into the rich and beautiful world of Python programming. From basics such as variables to data types and recursions, this document touches briefly on these concepts. It is not, by any means, an exhaustive guide to learn Python, but it serves as a good starting point and motivation.
Python is a high-level programming language that emphasizes code readability. It has a clear syntax and large standard library. Python can be used for system programming, GUIs, internet scripting, database programming, and more. Some key strengths of Python include being object-oriented, free, portable, powerful, easy to use and learn. Popular uses of Python include web development, scientific computing, and financial applications. The document provides an overview of Python fundamentals like data types, control flow statements, functions, classes, and modules.
Python is a widely used general-purpose programming language that is highly readable. It uses fewer syntactical constructions than other languages and supports object-oriented programming. The document discusses how Python defines classes with attributes and methods and is a dynamic language with high-level data types, making development faster than with Java or C++. It also covers topics that will be included in the Python training, such as classes and objects, inheritance, strings, lists, dictionaries, exceptions, multithreading, streams, and database connections. The training aims to help students master Python scripting fundamentals and acquire object-oriented skills.
Excellence Technology is one of the top ISO satisfied company in Chandigarh and Mohali . We provide Best industrial training Digital marketing, PHP.java, best web designing training ,software testing ,Python Course In Chandigarh etc . It can be provided 6 month and 28 days industrial training & tuition classes.
After the end of lesson you will be able to learn Python basics-What Python is? Its releases. Where we can use Python? Python Features. Tokens, comments variables etc... In out next PPT you will learn how to input and get output in Python
This document provides an industrial training presentation on Python programming. It introduces Python, explaining that it is an interpreted, object-oriented, high-level programming language. It then covers why Python is used, its basic data types like numbers, strings, lists, dictionaries, tuples and sets. The presentation also discusses Python concepts like conditionals, loops, functions, exceptions, file handling, object-oriented programming and databases. It concludes that Python supports both procedural and object-oriented programming and can be universally accepted. References for further reading are also included.
Introduction to Python for Data Science and Machine Learning ParrotAI
This document provides an introduction and overview of Python for data science and machine learning. It covers basics of Python including what Python is, its features, why it is useful for data science. It also discusses installing Python, using the IDLE and Jupyter Notebook environments. The document then covers Python basics like variables, data types, operators, decision making and loops. Finally, it discusses collection data types like lists, tuples and dictionaries and functions in Python.
The document provides an introduction to the Python programming language. It discusses what Python is, its creator Guido van Rossum, and how to write a simple "Hello World" program. It also covers Python data types, operators, flow control using conditionals and loops, functions, input/output operations, and the Zen of Python philosophy guiding Python's design. The document serves as the first day of instruction in a Python course.
Python and Perl are both high-level programming languages. Python is an interpreted language with clear, readable syntax and intuitive object orientation. Perl is also an interpreted and dynamic language that supports both procedural and object-oriented programming and is best known for powerful text processing. Both languages have a long history and are widely used for web development, scientific computing, and other tasks.
The type of a value refers to the kind of data it represents. In Python, the main types are:
- int - integer numbers like 1, 2, 100
- float - floating point numbers like 1.5, 3.14159
- str - strings, sequences of characters like 'hello'
- bool - boolean values True or False
When you write code, Python assigns a type to each value. The type determines how it can be used and what operations are valid on it. For example, you can add two integers but not add an integer to a string. Checking and understanding types is important for writing correct Python code.
ZENUS INFOTECH is best Python Training institute in Roorkee and an ISO 9001:2008 Certified Engineer’s Training Company in Roorkee & provides training to the B.E./B.TECH/DIPLOMA/MCA/BCA and related field students in 35+ cutting-edge technologies like AutoCAD, Solid-Works, CATIA, REVIT, Pro-E, UG-NX .NET, JAVA, PHP, GST Tally and Wireless & Telecommunication and many more.
This document provides an introduction to Python and the Pandas library. It begins with an overview of Python, describing its history, key features like readability and cross-platform compatibility. It then covers Python basics like variables, data types, operators, conditional and loop statements. Object-oriented concepts are explained like classes, methods and functions. Key data structures are defined, including lists, tuples, dictionaries and sets. The document concludes with an introduction to Pandas, describing its use for data analysis, cleaning, transformation and visualization.
Kunal Chauhan will be conducting a 6 week Python training program from May 15th to June 26th. The training will cover introductory Python programming, basics of programming in Python including variables, data types, operators, and control flow, principles of object-oriented programming, SQLite database usage, GUI development with PyQt, and applications of Python in various disciplines like web development, machine learning, data science, and more.
Here is the class Book with the requested attributes and member functions:
#include <iostream>
using namespace std;
class Book {
private:
string title;
string author;
string publisher;
float price;
public:
Book() {
title = "No title";
author = "No author";
publisher = "No publisher";
price = 0.0;
}
void display_data() {
cout << "Title: " << title << endl;
cout << "Author: " << author << endl;
cout << "Publisher: " << publisher << endl;
cout << "Price: " << price << endl;
}
This presentation is a great resource for zero-based Python programmers who wants to learn Python 3. This course includes brief history of Python and familiarity of its basic syntax.
Main Java[All of the Base Concepts}.docxadhitya5119
This is part 1 of my Java Learning Journey. This Contains Custom methods, classes, constructors, packages, multithreading , try- catch block, finally block and more.
This document provides an introduction to Python programming through a series of lectures. It begins with defining Python, what it can be used for, and why it is a popular language. It then covers Python syntax compared to other languages, getting started with Python including installation and running a simple program. The document continues with topics like Python variables, data types, strings, numbers, operators, and lists. It provides examples and explanations of core Python concepts to help newcomers learn the essentials of the language.
The document provides information about various Python concepts like PEP 8, pickling, lambda functions, generators, modules, packages and more. It also includes questions about memory management in Python, tools for static analysis, decorators, iterators, slicing, and other common Python interview questions.
This document provides an overview of Python programming in Katana for beginners. It discusses scripting languages and their advantages, different programming paradigms like procedural and object-oriented programming, and key Python concepts like data types, variables, functions, modules and packages. The document also demonstrates how to get started with Python in Katana, covering topics like syntax, comments, writing scripts and using the interactive console.
This file contains the first steps any beginner can take as he/she starts a journey into the rich and beautiful world of Python programming. From basics such as variables to data types and recursions, this document touches briefly on these concepts. It is not, by any means, an exhaustive guide to learn Python, but it serves as a good starting point and motivation.
Python is a high-level programming language that emphasizes code readability. It has a clear syntax and large standard library. Python can be used for system programming, GUIs, internet scripting, database programming, and more. Some key strengths of Python include being object-oriented, free, portable, powerful, easy to use and learn. Popular uses of Python include web development, scientific computing, and financial applications. The document provides an overview of Python fundamentals like data types, control flow statements, functions, classes, and modules.
Python is a widely used general-purpose programming language that is highly readable. It uses fewer syntactical constructions than other languages and supports object-oriented programming. The document discusses how Python defines classes with attributes and methods and is a dynamic language with high-level data types, making development faster than with Java or C++. It also covers topics that will be included in the Python training, such as classes and objects, inheritance, strings, lists, dictionaries, exceptions, multithreading, streams, and database connections. The training aims to help students master Python scripting fundamentals and acquire object-oriented skills.
Excellence Technology is one of the top ISO satisfied company in Chandigarh and Mohali . We provide Best industrial training Digital marketing, PHP.java, best web designing training ,software testing ,Python Course In Chandigarh etc . It can be provided 6 month and 28 days industrial training & tuition classes.
After the end of lesson you will be able to learn Python basics-What Python is? Its releases. Where we can use Python? Python Features. Tokens, comments variables etc... In out next PPT you will learn how to input and get output in Python
This document provides an industrial training presentation on Python programming. It introduces Python, explaining that it is an interpreted, object-oriented, high-level programming language. It then covers why Python is used, its basic data types like numbers, strings, lists, dictionaries, tuples and sets. The presentation also discusses Python concepts like conditionals, loops, functions, exceptions, file handling, object-oriented programming and databases. It concludes that Python supports both procedural and object-oriented programming and can be universally accepted. References for further reading are also included.
Introduction to Python for Data Science and Machine Learning ParrotAI
This document provides an introduction and overview of Python for data science and machine learning. It covers basics of Python including what Python is, its features, why it is useful for data science. It also discusses installing Python, using the IDLE and Jupyter Notebook environments. The document then covers Python basics like variables, data types, operators, decision making and loops. Finally, it discusses collection data types like lists, tuples and dictionaries and functions in Python.
The document provides an introduction to the Python programming language. It discusses what Python is, its creator Guido van Rossum, and how to write a simple "Hello World" program. It also covers Python data types, operators, flow control using conditionals and loops, functions, input/output operations, and the Zen of Python philosophy guiding Python's design. The document serves as the first day of instruction in a Python course.
Python and Perl are both high-level programming languages. Python is an interpreted language with clear, readable syntax and intuitive object orientation. Perl is also an interpreted and dynamic language that supports both procedural and object-oriented programming and is best known for powerful text processing. Both languages have a long history and are widely used for web development, scientific computing, and other tasks.
The type of a value refers to the kind of data it represents. In Python, the main types are:
- int - integer numbers like 1, 2, 100
- float - floating point numbers like 1.5, 3.14159
- str - strings, sequences of characters like 'hello'
- bool - boolean values True or False
When you write code, Python assigns a type to each value. The type determines how it can be used and what operations are valid on it. For example, you can add two integers but not add an integer to a string. Checking and understanding types is important for writing correct Python code.
ZENUS INFOTECH is best Python Training institute in Roorkee and an ISO 9001:2008 Certified Engineer’s Training Company in Roorkee & provides training to the B.E./B.TECH/DIPLOMA/MCA/BCA and related field students in 35+ cutting-edge technologies like AutoCAD, Solid-Works, CATIA, REVIT, Pro-E, UG-NX .NET, JAVA, PHP, GST Tally and Wireless & Telecommunication and many more.
This document provides an introduction to Python and the Pandas library. It begins with an overview of Python, describing its history, key features like readability and cross-platform compatibility. It then covers Python basics like variables, data types, operators, conditional and loop statements. Object-oriented concepts are explained like classes, methods and functions. Key data structures are defined, including lists, tuples, dictionaries and sets. The document concludes with an introduction to Pandas, describing its use for data analysis, cleaning, transformation and visualization.
Kunal Chauhan will be conducting a 6 week Python training program from May 15th to June 26th. The training will cover introductory Python programming, basics of programming in Python including variables, data types, operators, and control flow, principles of object-oriented programming, SQLite database usage, GUI development with PyQt, and applications of Python in various disciplines like web development, machine learning, data science, and more.
Here is the class Book with the requested attributes and member functions:
#include <iostream>
using namespace std;
class Book {
private:
string title;
string author;
string publisher;
float price;
public:
Book() {
title = "No title";
author = "No author";
publisher = "No publisher";
price = 0.0;
}
void display_data() {
cout << "Title: " << title << endl;
cout << "Author: " << author << endl;
cout << "Publisher: " << publisher << endl;
cout << "Price: " << price << endl;
}
This presentation is a great resource for zero-based Python programmers who wants to learn Python 3. This course includes brief history of Python and familiarity of its basic syntax.
Main Java[All of the Base Concepts}.docxadhitya5119
This is part 1 of my Java Learning Journey. This Contains Custom methods, classes, constructors, packages, multithreading , try- catch block, finally block and more.
How to Manage Your Lost Opportunities in Odoo 17 CRMCeline George
Odoo 17 CRM allows us to track why we lose sales opportunities with "Lost Reasons." This helps analyze our sales process and identify areas for improvement. Here's how to configure lost reasons in Odoo 17 CRM
A review of the growth of the Israel Genealogy Research Association Database Collection for the last 12 months. Our collection is now passed the 3 million mark and still growing. See which archives have contributed the most. See the different types of records we have, and which years have had records added. You can also see what we have for the future.
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
A workshop hosted by the South African Journal of Science aimed at postgraduate students and early career researchers with little or no experience in writing and publishing journal articles.
हिंदी वर्णमाला पीपीटी, hindi alphabet PPT presentation, hindi varnamala PPT, Hindi Varnamala pdf, हिंदी स्वर, हिंदी व्यंजन, sikhiye hindi varnmala, dr. mulla adam ali, hindi language and literature, hindi alphabet with drawing, hindi alphabet pdf, hindi varnamala for childrens, hindi language, hindi varnamala practice for kids, https://www.drmullaadamali.com
Thinking of getting a dog? Be aware that breeds like Pit Bulls, Rottweilers, and German Shepherds can be loyal and dangerous. Proper training and socialization are crucial to preventing aggressive behaviors. Ensure safety by understanding their needs and always supervising interactions. Stay safe, and enjoy your furry friends!
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
it describes the bony anatomy including the femoral head , acetabulum, labrum . also discusses the capsule , ligaments . muscle that act on the hip joint and the range of motion are outlined. factors affecting hip joint stability and weight transmission through the joint are summarized.
2. Introduction to Python
Python is a high-level programming language
Open source and community driven
“Batteries Included”
a standard distribution includes many modules
Dynamic typed
Source can be compiled or run just-in-time
Similar to perl, tcl, ruby
2
3. Why Python?
Unlike AML and Avenue, there is a considerable base
of developers already using the language
“Tried and true” language that has been in
development since 1991
Can interface with the Component Object Model
(COM) used by Windows
Can interface with Open Source GIS toolsets
3
4. Why not Visual Basic?
Visual Basic is still the method of configuring and
customizing ArcMap
If you have a button on the toolbar, it’s VB
Python scripts can be placed in ArcToolbox
Python can be run from the command line without
ArcMap or ArcCatalog being open
Using just the GIS Engine, lower overhead
Rapid prototyping, ease of authoring, etc.
4
5. Python Interfaces
IDLE – a cross-platform Python development
environment
PythonWin – a Windows only interface to Python
Python Shell – running 'python' from the Command
Line opens this interactive shell
For the exercises, we'll use IDLE, but you can try them
all and pick a favorite
5
6. IDLE – Development Environment
IDLE helps you program
in Python by:
color-coding your
program code
debugging
auto-indent
interactive shell
6
7. Example Python
Hello World
print “hello world”
Prints hello world to
standard out
Open IDLE and try it out
yourself
Follow along using IDLE
7
8. More than just printing
Python is an object oriented language
Practically everything can be treated as an object
“hello world” is a string
Strings, as objects, have methods that return the result
of a function on the string
8
9. String Methods
Assign a string to a
variable
In this case “hw”
hw.title()
hw.upper()
hw.isdigit()
hw.islower()
9
10. String Methods
The string held in your variable remains the same
The method returns an altered string
Changing the variable requires reassignment
hw = hw.upper()
hw now equals “HELLO WORLD”
10
11. Other Python Objects
Lists (mutable sets of strings)
var = [] # create list
var = [‘one’, 2, ‘three’, ‘banana’]
Tuples (immutable sets)
var = (‘one’, 2, ‘three’, ‘banana’)
Dictionaries (associative arrays or ‘hashes’)
var = {} # create dictionary
var = {‘lat’: 40.20547, ‘lon’: -74.76322}
var[‘lat’] = 40.2054
Each has its own set of methods
11
12. Lists
Think of a list as a stack of cards, on which your
information is written
The information stays in the order you place it in until
you modify that order
Methods return a string or subset of the list or modify
the list to add or remove components
Written as var[index], index refers to order within set
(think card number, starting at 0)
You can step through lists as part of a loop
12
13. List Methods
Adding to the List
var[n] = object
replaces n with object
var.append(object)
adds object to the end of the list
Removing from the List
var[n] = []
empties contents of card, but preserves order
var.remove(n)
removes card at n
var.pop(n)
removes n and returns its value
13
14. Lists in ArcToolbox
You will create lists:
Layers as inputs
Attributes to match
Arrays of objects
You will work with lists:
List of field names
List of selected features
14
15. Tuples
Like a list, tuples are iterable arrays of objects
Tuples are immutable –
once created, unchangeable
To add or remove items, you must redeclare
Example uses of tuples
County Names
Land Use Codes
Ordered set of functions
15
16. Dictionaries
Dictionaries are sets of key & value pairs
Allows you to identify values by a descriptive name
instead of order in a list
Keys are unordered unless explicitly sorted
Keys are unique:
var[‘item’] = “apple”
var[‘item’] = “banana”
print var[‘item’] prints just banana
16
17. Indentation and Blocks
Python uses whitespace and indents to denote blocks
of code
Lines of code that begin a block end in a colon:
Lines within the code block are indented at the same
level
To end a code block, remove the indentation
You'll want blocks of code that run only when certain
conditions are met
17
18. Conditional Branching
if and else
if variable == condition:
#do something based on v == c
else:
#do something based on v != c
elif allows for additional branching
if condition:
elif another condition:
…
else: #none of the above
18
19. Looping with For
For allows you to loop over a block of code a set
number of times
For is great for manipulating lists:
a = ['cat', 'window', 'defenestrate']
for x in a:
print x, len(x)
Results:
cat 3
window 6
defenestrate 12
19
20. Looping with For
We could use a for loop to perform geoprocessing tasks
on each layer in a list
We could get a list of features in a feature class and
loop over each, checking attributes
Anything in a sequence or list can be used in a For loop
Just be sure not to modify the list while looping
20
21. Modules
Modules are additional pieces of code that further
extend Python’s functionality
A module typically has a specific function
additional math functions, databases, network…
Python comes with many useful modules
arcgisscripting is the module we will use to load
ArcGIS toolbox functions into Python
21
22. Modules
Modules are accessed using import
import sys, os # imports two modules
Modules can have subsets of functions
os.path is a subset within os
Modules are then addressed by
modulename.function()
sys.argv # list of arguments
filename = os.path.splitext("points.txt")
filename[1] # equals ".txt"
22
23. Files
Files are manipulated by creating a file object
f = open("points.txt", "r")
The file object then has new methods
print f.readline() # prints line from file
Files can be accessed to read or write
f = open("output.txt", "w")
f.write("Important Output!")
Files are iterable objects, like lists
23
24. Error Capture
Check for type assignment errors, items not in a list,
etc.
Try & Except
try:
a block of code that might have an error
except:
code to execute if an error occurs in "try"
Allows for graceful failure
– important in ArcGIS
24
26. What Is a Program?
Usually, one or more algorithms written in a
programming language that can be translated to run
on a real machine
We sometimes call programs software
27. What Is a Programming Language?
A programming language is somewhat like a
natural language, but with a very limited set of
statements and strict syntax rules.
Has statements to implement sequential,
conditional and iterative processing - algorithms
Examples: FORTRAN, COBOL, Lisp, Basic, Pascal,
C, C++, Java, C#, Python, …
28. Compiler
A compiler is a program that converts a program
written in a programming language into a program in
the native language, called machine language, of the
machine that is to execute the program.
29. From Algorithms to Hardware
(with compiler)
Algorithm
Program
A real computer
Translate (by a human being)
Translate (by compiler program)
30. The Program Development Process
(Data Flow)
Editor
Compiler
A real computer
Algorithm
Program in programming language
Program in machine’s language
Input Output
31. The Program Development Process
(Control Flow)
Edit
Compile
Run
Syntax errors
Input Output
Runtime errors
32. Three kinds of errors
Syntax error : Some statement in the program is not a
legal statement in the language.
Runtime error : An error occurs while the program is
executing, causing the program to terminate (divide by
zero, etc.)
Logic error : The program executes to completion, but
gives incorrect results.
33. Interpreter
An alternative to a compiler is a program called an
interpreter. Rather than convert our program to the
language of the computer, the interpreter takes our
program one statement at a time and executes a
corresponding set of machine instructions.
35. Python
Python is a real-world, production language that is freely available
for most computers.
http:www.python.org
If you want a copy of Python to use with this course, go to
http://code.google.com/p/mediacomp-jes/ .
We are using JES (Jython Environment for Students) which has a
lot of special multimedia functionality.
Note: Our textbook covers a limited amount of Python. There are
many excellent online tutorials. For example, see
http://en.wikibooks.org/wiki/Non-Programmer's_Tutorial_for_Python/Contents
36. Python
Python uses an interpreter. Not only can we write complete
programs, we can work with the interpreter in a statement by
statement mode enabling us to experiment quite easily.
Python is especially good for our purposes in that it does not
have a lot of “overhead” before getting started.
It is easy to jump in and experiment with Python in an
interactive fashion.
37. Language terminology
Syntax: The formal rules for legal statements in the
language.
Semantics: The meaning of the statements - what
happens when the statement is executed.
38. Three major control constructs
of programming
(Execution flow of instructions)
Sequential: Simply do steps one after the other in
order they are listed.
Conditional: Decide which statement to do next
based on some true/false test.
Iterative: A set of statements is repeated over and over
until some condition is met.
40. The Big Plan
We want to get some experience of programming simple
algorithms in a real programming language. This gives us an
understanding of how software is written and allows us to
test our algorithms to see if they work.
We’ll first work with programs where the variables have
numbers as values.
Later we’ll work with programs dealing with pictures and
sound.
In lab we’ll work with some simple statements and small
programs.
41. The Basic Pattern
Most of our programs will use the basic pattern of
Get some user input
Perform some algorithm on the input
Provide results as output
42. Identifiers
Identifiers are names of various program elements
in the code that uniquely identify the elements.
They are the names of things like variables or
functions to be performed. They're specified by the
programmer and should have names that indicate
their purpose.
In Python, identifiers
Are made of letters, digits and underscores
Must begin with a letter or an underscore
Examples: temperature, myPayrate, score2
43. Keywords
Keywords are reserved words that have special
meaning in the Python language. Because they are
reserved, they can not be used as identifiers. Examples
of keywords are if, while, class, import.
44. Variables in Python
A variable has
A name – identifier
A data type - int, float, str, etc.
Storage space sufficient for the type.
45. Numeric Data Types
int
This type is for whole numbers, positive or
negative. Examples: 23, -1756
float
This type is for numbers with possible fraction
parts. Examples: 23.0, -14.561
46. Integer operators
The operations for integers are:
+ for addition
- for subtraction
* for multiplication
/ for integer division: The result of 14/5 is 2
% for remainder: The result of 14 % 5 is 4
*, /, % take precedence over +, -
x + y * z will do y*z first
Use parentheses to dictate order you want.
(x+y) * z will do x+y first.
47. Integer Expressions
Integer expressions are formed using
Integer Constants
Integer Variables
Integer Operators
Parentheses
48. Python Assignment Statements
In Python, = is called the assignment operator and
an assignment statement has the form
<variable> = <expression>
Here
<variable> would be replaced by an actual variable
<expression> would be replaced by an expression
Python: age = 19
49. Python Assignment Statement
Syntax: <variable> = <expression>
Note that variable is on left
Semantics:
Compute value of expression
Store this as new value of the variable
Example: Pay = PayRate * Hours
Payrate
10
Hours
40
Pay
400
53. What about floats?
When computing with floats, / will indicate regular
division with fractional results.
Constants will have a decimal point.
14.0/5.0 will give 2.8 while 14/5 gives 2.
54. Comments
Often we want to put some documentation in our
program. These are comments for explanation, but not
executed by the computer.
If we have # anywhere on a line, everything following
this on the line is a comment – ignored
55. Numerical Input
To get numerical input from the user, we use an
assignment statement of the form
<variable> = input(<prompt>)
Here
<prompt> would be replaced by a prompt for the user
inside quotation marks
If there is no prompt, the parentheses are still needed
Semantics
The prompt will be displayed
User enters number
Value entered is stored as the value of the variable
56. Print Statement
For output we use statements of the form
print <expression>
Semantics
Value of expression is computed
This value is displayed
Several expressions can be printed – separate them by
commas
57. Example - Fahrenheit to Centigrade
We want to convert a Fahrenheit temperature to
Centigrade.
The formula is C = (F -32) x 5/9
We use type float for the temperatures.