Python for ArcGIS. Lab 1.

Size: px
Start display at page:

Download "Python for ArcGIS. Lab 1."

Transcription

1 Python for ArcGIS. Lab 1. Python is relatively new language of programming, which first implementation arrived around early nineties of the last century. It is best described as a high level and general purpose language, that places emphasis on ease of code understanding and possibility of expression of an idea while being size conservative. It allows to write structural programs, as well as object oriented ones, along with possibility of dividing code into smaller parts, which can be imported as modules. Python is considered as easy to learn, as its syntax is a natural English derivative, and it has significantly less special cases than other languages. Additionally scripts written in this language can be run without modification on multiple operating systems. 1. Python basics To get acquainted with language basics we will going to use Python console available thorough IDLE integrated development environment (IDE). It is located in Start Menu inside ArcGIS Ptython 2.7 submenu. It allows for sending direct expressions into interpreter. In case where there will be many expressions at once to evaluate we are going to write scripts. For that purpose integrated script editor inside IDLE will be used, but any text editor can be utilized for this purpose.there is special character # which means any text behind it is ignored by Python interpreter. It shoul be also noted that almost any data used in Python is an object, even simple string type. What this entails is that they can have various methods defined for them. Python reference documentation can be found here: Data types, variables, operators and data agregates Most programming languages require variables to be declared before usage. Python deemed that unnecessary therefore declaration occurs dynamically in the moment of data assignment. Basic data types are integers (int), floating point numbers (float), and character strings (str). Data, or object, assignment happens thorough usage of = operator. Assignment examples can be run in Python console entering expressions below: a=1 # assingment of object int 1 to variable a b="test" # assingment of object str to variable b c=1.0 # assingment of object float to variable c Next the type of defined variables can be verified using type() function: type(a) Displayed information should equal to types of int, str and float accordingly. It is worth noticing that floating number can be forced thorough comma operator, even if value which is assigned technically is an integer. Data assigned to variables are objects, and variables are references to those objects. Simple data types are immutable, therefore their content can not be changes. Hence during repeated assignment to the same variable its current data is discarded and new object is created. It has repercussions in case of strings for example, where its fragments cant be modified. To achieve such a goal new object shall be created which will contain selected substrings. This operation is called slicing and square brackets are used to that effect as subscripts. Also it is worth mentioning that we count them from zero. 'Kate has a cat'[3:8] # slice out characters 4th to 8th from object b[:2] # slice from beginning to positon 2 (from zero) ('Our '+b)[-6:] # slice starting from 6 characters counting backwards

2 In Python there os also special object called None which assignment of means that variable does not have any value, therefore does not reference any object. String data type can be marked thorough single quote or double quote. Stings, as an object, contain dozens of methods, which can be examined at following address: b.capitalize() # Capitalizes string 'Kate has a cat'.find('cat') # returns 'cat' substring position Apart from simple types such as numbers and strings there are aggregate types available such as list (ordered), set (unordred) or dictionary, and their non mutable versions, namely tuple (ordered) and frozenset (unorderd). It should be noted that lists can contain different simple data types.: lista=['wpis 0', 'wpis 1', 2, 'wpis 3', 2.0] zbior=set(('wpis 0', 'wpis 1', 2, 'wpis 3', 2.0)) tupla=('wpis 0', 'wpis 1', 2, 'wpis 3', 2.0) zbiorz=frozenset(('wpis 0', 'wpis 1', 2, 'wpis 3', 2.0)) slownik={0: 'wpis 0', 1:'wpis 1', 'drugi':2, 'trzeci':'wpis 3', 4:2.0} To display defined assignments we can use print operator and type() function: print lista print zbior print tupla[3] print slownik['trzeci'] type(zbiorz) After displaying defined variables it is easy to notice difference between ordered and unordered data aggregates. On the other hand difference between mutable and non mutable versions are far less obvious, but they become clear once we take into account, for example, that dictionary structure requires key values, which have to be unique as well as immutable. Other operators can be applied to objects and variables which are referencing them, for example arithmetic: 2+5 # addind int objects a-3 # substraction of and int variable and int object a*c # multiplication of int and float types c/2 # division of float variable and integer object Without assignment operator console interpreter will display value by default, however it isn't exactly equivalent to print operator. It should be noted that when artithmetic operations are performed on two distinct data types such as int and float then float type data is returned. Addition and multiplication operations also can be applied to the strings: abc +' aaa' # string addition b*3 # string multiplication b[:1]+b[2:] # slicing out second character from string Also slicing can be performed on ordered lists, similar to strings: tupla[2:3] lista[3:] Apart form arithmetic operators there are also comparison and logical ones. Comparison operators allow to check if and how objects differ from each other: 10 == 10 10!= >= 3 23 < 3 'cat' == 'dog' 'cat'!= 'dog'

3 Outcome of those expressions will answer true or false, otherwise known as logical value of 0 (False) or 1 (True). Logical value can be joined according to the truth table: And Or Not 1 and 1 = 1 1 or 1 = 1 not 1 = 0 1 and 0 = 0 1 or 0 = 1 not 0 = 1 0 and 1 = 0 0 or 1 = 1 0 and 0 = 0 0 or 0 = 0 Therefore example expressions containing those elements can look like this: 10 == 10 or 10>=3 # true, because one condition is true 3 < 4 and 4 < 10 # true, because both condifions are true 3 < 4 < 10 # true, shorter notation of the above 6 < 4 < 10 # false, one of the conditions is false There are sometimes situations, when we have to display characters which cant be entered directly form keyboard, because they are not printed or conflict with language syntax. It occurs most often when we need to break a new line, or display quotes. To do this we have to resort to one of the available escape sequences. Most popular are: \n ASCII linefeed (LF) new line \r ASCII Carriage Return (CR) second character of new line (Windows CR/LF) \' single quote \" double quote \\ backslash (\) \a ASCII bell (BEL) \b ASCII backspace (BS) \t ASCII Horizontal Tab (TAB) Example string representing usage of escape sequence can look like this: print Kate has a cat \n by the name of \ Snowball\ Different situation in which we need additional control is displaying variable values as a part of text strings. In this case we can use formatting operator, which in connection with conversion types is interpreted by print operator: zmienne = ('test', 1323, ) # defining tuple print 'Testing var display: string %s, number int %d, float %f' % zmienne From example we can deduce that print operator is using consequent values from list, and interpreting them relaying on formatting operator and then displaying it. It can be enhanced further through usage of dictionary which has strings as keys: slow={'k0':'test', 'k1':1323, 'k2':21.432} # define dictionary print 'Numbers float %(k2)f, int %(k1)d, and string %(k0)s' % slow Also when we need to just display % character without formatting we can use %%. print('testing %%d %d %%d') % 3 Complete conversion table and additional flag values can be found following this address:

4 1.2 Scripts and flow control The combination of different commands in one program requires you to create a text file containing those commands, and depending on the language that is used appropriate formatting rules must be respected. In the case of Python source code files traditionally have the extension ".py", but properly formatted file with a different extension also executes correctly. Such files are usually called scripts, because its complation to machine code is not required before execution, if the computer on which they are written, has a given language interpreter installed. During the first execution of the script Python interpreter creates a file with the extension ".pyc", which contains a compiled version of the script, and it is used as long as the source code in the script will not change. You can force a recompile by deleting the file ".pyc". Python syntax does not require parentheses, colons or are the keywords to mark the program block. Used for this purpose is suitably adjusted indentation, by adding a space at the beginning of the line. That means properly written program is at the same time well formatted and aesthetically pleasing. The script file can be created using any editor, for example, a standard notepad. However, to get the syntax highlighting is good to use another program such as Notepad++. The first simple program can be written by combining the following expressions: a=9 b=3 wyn=9+3 print 'Addition ',a,' i ', b, ' : ', wyn To create such script we are going to use IDLE and its built-in editor, by selecting File New Window. Then we have to enter our experessions, and upon completion, we have to save file, and then run the script using menus Run Run module, or by pressing F5 function key. Before beginning of further program modification, it is worth noting that the variables of the python in principle can have any name, if it does not interfere with the reserved keywords, namely: and as assert break class continue def del elif else except exec finally for from global if import in is lambda not or pass print raise return try while with yield In addition to these keywords standard implementation includes of course a lot of functions and methods, but they have parenthesis after the name, so there is no risk of conflict. In virtually every program there is a place where, according to some values we want to make the program accomplish another operation than the default. In this situation, we will use the structures 'if..else'. It is single most important construct you can think of, as without it there would not be possible to write programs as we know it: print 'Do you want to continue (t/n)?' k=raw_input() if k == 't': print 'Going through with execution' elif k == 'n': print 'Ending program' exit() else: print 'Wrong key pressed' New used function raw_input() reads the entered value from the keyboard, treating entered values as a string without evaluating its contents. Admittedly a command from the first script may be entered manually in the console of Python, but often we have to do a lot of similar operations, where manual insertion would be too burdensome. With the help comes construction of the loop, where you can use one of the two: while or for. While

5 construction is carried out as long as the controlling condition is true : print 'Guess number 1 to 9' while input()!= 8: print 'Wrong answer!' print 'Bingo!' # is numner correct # if not # if yes New function input () reads the entered value from the keyboard and evaluates it according to Python rules, then it is checked whether the value is different from eight. The loop will execute as long as this condition is true. Attention should be placed on the aforementioned indentation, which in this case controls which part of the code is performed in the loop. Another version of the loop in the language is construction 'for' and unlike 'while' does not use condition, only a defined range of values: print 'Enumerating values 0-99: ', for i in range(100): print i,' ', print '\nkoniec enumeracji.' # wyświetl kolejną liczbę It should be noted at the end of the operator 'print' there is a comma. This means that we do not want the end of the line displayed. You may also note that the argument of the operator 'print' appeared as a sign '\n'. This is called the escape character and allows you to display characters that are not on the keyboard, for example. end of the line, as is the case here. A new operator 'in' checks whether the value is in the set. New function 'range ()' creates a list of numerical values of the specified range, and it has two possible forms, one we used 'range(stop)', but it can be called with 3 arguments 'range(start,stop,step)': range(100, 10, -5) # generate list of decreasing values Expanding the program further, we can conclude that some portions are too long, and we would like to break them into smaller pieces. We will use then the structure function, which is a separate block that can be called from anywhere and, if necessary, receive parameters: def dodaj(a,b): c=a+b return c print dodaj(2,3) wyn=dodaj print wyn(3,4) # function definition # returns value # beginning of the main program, function call # function can be referenced by variable as well # function call through variable We can also create functions that have optional parameters: def mnoz(a,b=none): # function definition if b==none: c=a*a else: c=a*b return c # returns value print mnoz(2,3) print mnoz(4) # beginning of the main program, function call wyn=mnoz print wyn(3) print wyn(32,12)

Chapter 3 : Informatics Practices. Class XI ( As per CBSE Board) Python Fundamentals. Visit : python.mykvs.in for regular updates

Chapter 3 : Informatics Practices. Class XI ( As per CBSE Board) Python Fundamentals. Visit : python.mykvs.in for regular updates Chapter 3 : Informatics Practices Class XI ( As per CBSE Board) Python Fundamentals Introduction Python 3.0 was released in 2008. Although this version is supposed to be backward incompatibles, later on

More information

There are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu)

There are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu) I. INTERACTIVE MODE VERSUS SCRIPT MODE There are two ways to use the python interpreter: interactive mode and script mode. 1. Interactive Mode (a) open a terminal shell (terminal emulator in Applications

More information

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines. Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

There are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu)

There are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu) I. INTERACTIVE MODE VERSUS SCRIPT MODE There are two ways to use the python interpreter: interactive mode and script mode. 1. Interactive Mode (a) open a terminal shell (terminal emulator in Applications

More information

Variable and Data Type I

Variable and Data Type I Islamic University Of Gaza Faculty of Engineering Computer Engineering Department Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad September 24, 2016 Variable is reserved a location in memory to store

More information

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

More information

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

More information

Variable and Data Type I

Variable and Data Type I The Islamic University of Gaza Faculty of Engineering Dept. of Computer Engineering Intro. To Computers (LNGG 1003) Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad February 18, 2017 Variable is reserved

More information

Senthil Kumaran S

Senthil Kumaran S Senthil Kumaran S http://www.stylesen.org/ Agenda History Basics Control Flow Functions Modules History What is Python? Python is a general purpose, object-oriented, high level, interpreted language Created

More information

Getting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an . Michigan State University CSE 231, Fall 2013

Getting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an  . Michigan State University CSE 231, Fall 2013 CSE 231, Rich Enbody Office Hours After class By appointment send an email 2 1 Project 1 Python arithmetic Do with pencil, paper and calculator first Idle Handin Help room 3 What is a Computer Program?

More information

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

Python I. Some material adapted from Upenn cmpe391 slides and other sources

Python I. Some material adapted from Upenn cmpe391 slides and other sources Python I Some material adapted from Upenn cmpe391 slides and other sources Overview Names & Assignment Data types Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics

More information

CS Summer 2013

CS Summer 2013 CS 1110 - Summer 2013 intro to programming -- how to think like a robot :) we use the Python* language (www.python.org) programming environments (many choices): Eclipse (free from www.eclipse.org), or

More information

Maciej Sobieraj. Lecture 1

Maciej Sobieraj. Lecture 1 Maciej Sobieraj Lecture 1 Outline 1. Introduction to computer programming 2. Advanced flow control and data aggregates Your first program First we need to define our expectations for the program. They

More information

Introduction to Computer Programming CSCI-UA 2. Review Midterm Exam 1

Introduction to Computer Programming CSCI-UA 2. Review Midterm Exam 1 Review Midterm Exam 1 Review Midterm Exam 1 Exam on Monday, October 7 Data Types and Variables = Data Types and Variables Basic Data Types Integers Floating Point Numbers Strings Data Types and Variables

More information

Advanced Algorithms and Computational Models (module A)

Advanced Algorithms and Computational Models (module A) Advanced Algorithms and Computational Models (module A) Giacomo Fiumara giacomo.fiumara@unime.it 2014-2015 1 / 34 Python's built-in classes A class is immutable if each object of that class has a xed value

More information

CHAPTER 2: Introduction to Python COMPUTER PROGRAMMING SKILLS

CHAPTER 2: Introduction to Python COMPUTER PROGRAMMING SKILLS CHAPTER 2: Introduction to Python COMPUTER PROGRAMMING SKILLS 1439-1440 1 Outline 1. Introduction 2. Why Python? 3. Compiler and Interpreter 4. The first program 5. Comments and Docstrings 6. Python Indentations

More information

06/11/2014. Subjects. CS Applied Robotics Lab Gerardo Carmona :: makeroboticsprojects.com June / ) Beginning with Python

06/11/2014. Subjects. CS Applied Robotics Lab Gerardo Carmona :: makeroboticsprojects.com June / ) Beginning with Python CS95003 - Applied Robotics Lab Gerardo Carmona :: makeroboticsprojects.com June / 2014 Subjects 1) Beginning with Python 2) Variables 3) Strings 4) Basic arithmetic operators 5) Flow control 6) Comparison

More information

GIS 4653/5653: Spatial Programming and GIS. More Python: Statements, Types, Functions, Modules, Classes

GIS 4653/5653: Spatial Programming and GIS. More Python: Statements, Types, Functions, Modules, Classes GIS 4653/5653: Spatial Programming and GIS More Python: Statements, Types, Functions, Modules, Classes Statement Syntax The if-elif-else statement Indentation and and colons are important Parentheses and

More information

age = 23 age = age + 1 data types Integers Floating-point numbers Strings Booleans loosely typed age = In my 20s

age = 23 age = age + 1 data types Integers Floating-point numbers Strings Booleans loosely typed age = In my 20s Intro to Python Python Getting increasingly more common Designed to have intuitive and lightweight syntax In this class, we will be using Python 3.x Python 2.x is still very popular, and the differences

More information

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals: Numeric Types There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals: 1-123 +456 2. Long integers, of unlimited

More information

CSCE 110 Programming I

CSCE 110 Programming I CSCE 110 Programming I Basics of Python (Part 1): Variables, Expressions, and Input/Output Dr. Tiffani L. Williams Department of Computer Science and Engineering Texas A&M University Spring 2013 Tiffani

More information

CSCE 110 Programming I Basics of Python: Variables, Expressions, Input/Output

CSCE 110 Programming I Basics of Python: Variables, Expressions, Input/Output CSCE 110 Programming I Basics of Python: Variables, Expressions, Input/Output Dr. Tiffani L. Williams Department of Computer Science and Engineering Texas A&M University Spring 2011 Python Python was developed

More information

Chapter 2 Input, Processing and Output. Hong Sun COSC 1436 Spring 2017 Jan 30, 2017

Chapter 2 Input, Processing and Output. Hong Sun COSC 1436 Spring 2017 Jan 30, 2017 Chapter 2 Input, Processing and Output Hong Sun COSC 1436 Spring 2017 Jan 30, 2017 Designing a Program Designing a Program o Programs must be carefully designed before they are written. Before beginning

More information

Introduction to Python

Introduction to Python Introduction to Python خانه ریاضیات اصفهان فرزانه کاظمی زمستان 93 1 Why Python? Python is free. Python easy to lean and use. Reduce time and length of coding. Huge standard library Simple (Python code

More information

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program Overview - General Data Types - Categories of Words - The Three S s - Define Before Use - End of Statement - My First Program a description of data, defining a set of valid values and operations List of

More information

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance. 2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C

More information

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D 1/58 Interactive use $ python Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information.

More information

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D 1/60 Interactive use $ python Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information.

More information

Beyond Blocks: Python Session #1

Beyond Blocks: Python Session #1 Beyond Blocks: Session #1 CS10 Spring 2013 Thursday, April 30, 2013 Michael Ball Beyond Blocks : : Session #1 by Michael Ball adapted from Glenn Sugden is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike

More information

Introduction to Python Programming

Introduction to Python Programming 2 Introduction to Python Programming Objectives To understand a typical Python program-development environment. To write simple computer programs in Python. To use simple input and output statements. To

More information

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0. L J Howell UX Software Ver. 1.0

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0. L J Howell UX Software Ver. 1.0 VISUAL GUIDE to RX Scripting for Roulette Xtreme - System Designer 2.0 L J Howell UX Software 2009 Ver. 1.0 TABLE OF CONTENTS INTRODUCTION...ii What is this book about?... iii How to use this book... iii

More information

PYTHON FOR KIDS A Pl ayfu l I ntrodu ctio n to Prog r am m i ng J a s o n R. B r i g g s

PYTHON FOR KIDS A Pl ayfu l I ntrodu ctio n to Prog r am m i ng J a s o n R. B r i g g s PYTHON FO R K I D S A P l ay f u l I n t r o d u c t i o n to P r o g r a m m i n g Jason R. Briggs Index Symbols and Numbers + (addition operator), 17 \ (backslash) to separate lines of code, 235 in strings,

More information

Variables and data types

Variables and data types Programming with Python Module 1 Variables and data types Theoretical part Contents 1 Module overview 4 2 Writing computer programs 4 2.1 Computer programs consist of data and instructions......... 4 2.2

More information

CHAD Language Reference Manual

CHAD Language Reference Manual CHAD Language Reference Manual INTRODUCTION The CHAD programming language is a limited purpose programming language designed to allow teachers and students to quickly code algorithms involving arrays,

More information

Accelerating Information Technology Innovation

Accelerating Information Technology Innovation Accelerating Information Technology Innovation http://aiti.mit.edu Cali, Colombia Summer 2012 Lesson 1 Introduction to Python Agenda What is Python? and Why Python? Basic Syntax Strings User Input Useful

More information

The Three Rules. Program. What is a Computer Program? 5/30/2018. Interpreted. Your First Program QuickStart 1. Chapter 1

The Three Rules. Program. What is a Computer Program? 5/30/2018. Interpreted. Your First Program QuickStart 1. Chapter 1 The Three Rules Chapter 1 Beginnings Rule 1: Think before you program Rule 2: A program is a human-readable essay on problem solving that also executes on a computer Rule 3: The best way to improve your

More information

Full file at C How to Program, 6/e Multiple Choice Test Bank

Full file at   C How to Program, 6/e Multiple Choice Test Bank 2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)

More information

Chapter 2 Getting Started with Python

Chapter 2 Getting Started with Python Chapter 2 Getting Started with Python Introduction Python Programming language was developed by Guido Van Rossum in February 1991. It is based on or influenced with two programming languages: 1. ABC language,

More information

Python: common syntax

Python: common syntax Lab 09 Python! Python Intro Main Differences from C++: True and False are capitals Python floors (always down) with int division (matters with negatives): -3 / 2 = -2 No variable data types or variable

More information

CIS192 Python Programming. Robert Rand. August 27, 2015

CIS192 Python Programming. Robert Rand. August 27, 2015 CIS192 Python Programming Introduction Robert Rand University of Pennsylvania August 27, 2015 Robert Rand (University of Pennsylvania) CIS 192 August 27, 2015 1 / 30 Outline 1 Logistics Grading Office

More information

And Parallelism. Parallelism in Prolog. OR Parallelism

And Parallelism. Parallelism in Prolog. OR Parallelism Parallelism in Prolog And Parallelism One reason that Prolog is of interest to computer scientists is that its search mechanism lends itself to parallel evaluation. In fact, it supports two different kinds

More information

Basic Scripting, Syntax, and Data Types in Python. Mteor 227 Fall 2017

Basic Scripting, Syntax, and Data Types in Python. Mteor 227 Fall 2017 Basic Scripting, Syntax, and Data Types in Python Mteor 227 Fall 2017 Basic Shell Scripting/Programming with Python Shell: a user interface for access to an operating system s services. The outer layer

More information

STEAM Clown & Productions Copyright 2017 STEAM Clown. Page 1

STEAM Clown & Productions Copyright 2017 STEAM Clown. Page 1 What to add next time you are updating these slides Update slides to have more animation in the bullet lists Verify that each slide has stand alone speaker notes Page 1 Python 3 Running The Python Interpreter

More information

CS2304: Python for Java Programmers. CS2304: Sequences and Collections

CS2304: Python for Java Programmers. CS2304: Sequences and Collections CS2304: Sequences and Collections Sequences In Python A sequence type in python supports: The in membership operator. The len() function. Slicing like we saw with strings, s[1:3]. And is iterable (for

More information

Some material adapted from Upenn cmpe391 slides and other sources

Some material adapted from Upenn cmpe391 slides and other sources Some material adapted from Upenn cmpe391 slides and other sources History Installing & Running Python Names & Assignment Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics

More information

History Installing & Running Python Names & Assignment Sequences types: Lists, Tuples, and Strings Mutability

History Installing & Running Python Names & Assignment Sequences types: Lists, Tuples, and Strings Mutability History Installing & Running Python Names & Assignment Sequences types: Lists, Tuples, and Strings Mutability Some material adapted from Upenn cmpe391 slides and other sources Invented in the Netherlands,

More information

Chapter 2 Writing Simple Programs

Chapter 2 Writing Simple Programs Chapter 2 Writing Simple Programs Charles Severance Textbook: Python Programming: An Introduction to Computer Science, John Zelle (www.si182.com) Software Development Process Figure out the problem - for

More information

Introduction to Python, Cplex and Gurobi

Introduction to Python, Cplex and Gurobi Introduction to Python, Cplex and Gurobi Introduction Python is a widely used, high level programming language designed by Guido van Rossum and released on 1991. Two stable releases: Python 2.7 Python

More information

Python Basics. Lecture and Lab 5 Day Course. Python Basics

Python Basics. Lecture and Lab 5 Day Course. Python Basics Python Basics Lecture and Lab 5 Day Course Course Overview Python, is an interpreted, object-oriented, high-level language that can get work done in a hurry. A tool that can improve all professionals ability

More information

Java Bytecode (binary file)

Java Bytecode (binary file) Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.

More information

Flow Control: Branches and loops

Flow Control: Branches and loops Flow Control: Branches and loops In this context flow control refers to controlling the flow of the execution of your program that is, which instructions will get carried out and in what order. In the

More information

Python Intro GIS Week 1. Jake K. Carr

Python Intro GIS Week 1. Jake K. Carr GIS 5222 Week 1 Why Python It s simple and easy to learn It s free - open source! It s cross platform IT S expandable!! Why Python: Example Consider having to convert 1,000 shapefiles into feature classes

More information

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

More information

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI CSCI 2010 Principles of Computer Science Data and Expressions 08/09/2013 CSCI 2010 1 Data Types, Variables and Expressions in Java We look at the primitive data types, strings and expressions that are

More information

Data Structures. Lists, Tuples, Sets, Dictionaries

Data Structures. Lists, Tuples, Sets, Dictionaries Data Structures Lists, Tuples, Sets, Dictionaries Collections Programs work with simple values: integers, floats, booleans, strings Often, however, we need to work with collections of values (customers,

More information

VLC : Language Reference Manual

VLC : Language Reference Manual VLC : Language Reference Manual Table Of Contents 1. Introduction 2. Types and Declarations 2a. Primitives 2b. Non-primitives - Strings - Arrays 3. Lexical conventions 3a. Whitespace 3b. Comments 3c. Identifiers

More information

Table of Contents EVALUATION COPY

Table of Contents EVALUATION COPY Table of Contents Introduction... 1-2 A Brief History of Python... 1-3 Python Versions... 1-4 Installing Python... 1-5 Environment Variables... 1-6 Executing Python from the Command Line... 1-7 IDLE...

More information

Variables, expressions and statements

Variables, expressions and statements Variables, expressions and statements 2.1. Values and data types A value is one of the fundamental things like a letter or a number that a program manipulates. The values we have seen so far are 2 (the

More information

Working with Strings. Husni. "The Practice of Computing Using Python", Punch & Enbody, Copyright 2013 Pearson Education, Inc.

Working with Strings. Husni. The Practice of Computing Using Python, Punch & Enbody, Copyright 2013 Pearson Education, Inc. Working with Strings Husni "The Practice of Computing Using Python", Punch & Enbody, Copyright 2013 Pearson Education, Inc. Sequence of characters We've talked about strings being a sequence of characters.

More information

Sequence of Characters. Non-printing Characters. And Then There Is """ """ Subset of UTF-8. String Representation 6/5/2018.

Sequence of Characters. Non-printing Characters. And Then There Is   Subset of UTF-8. String Representation 6/5/2018. Chapter 4 Working with Strings Sequence of Characters we've talked about strings being a sequence of characters. a string is indicated between ' ' or " " the exact sequence of characters is maintained

More information

Accelerating Information Technology Innovation

Accelerating Information Technology Innovation Accelerating Information Technology Innovation http://aiti.mit.edu/program/philippines-summer-2012/ Philippines Summer 2012 Lecture 1 Introduction to Python June 19, 2012 Agenda About the Course What is

More information

ENGR 101 Engineering Design Workshop

ENGR 101 Engineering Design Workshop ENGR 101 Engineering Design Workshop Lecture 2: Variables, Statements/Expressions, if-else Edgardo Molina City College of New York Literals, Variables, Data Types, Statements and Expressions Python as

More information

The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

More information

SPARK-PL: Introduction

SPARK-PL: Introduction Alexey Solovyev Abstract All basic elements of SPARK-PL are introduced. Table of Contents 1. Introduction to SPARK-PL... 1 2. Alphabet of SPARK-PL... 3 3. Types and variables... 3 4. SPARK-PL basic commands...

More information

Python. Objects. Geog 271 Geographic Data Analysis Fall 2010

Python. Objects. Geog 271 Geographic Data Analysis Fall 2010 Python This handout covers a very small subset of the Python language, nearly sufficient for exercises in this course. The rest of the language and its libraries are covered in many fine books and in free

More information

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

CMSC 201 Fall 2016 Lab 09 Advanced Debugging CMSC 201 Fall 2016 Lab 09 Advanced Debugging Assignment: Lab 09 Advanced Debugging Due Date: During discussion Value: 10 points Part 1: Introduction to Errors Throughout this semester, we have been working

More information

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid:

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid: 1 STRINGS Objectives: How text data is internally represented as a string Accessing individual characters by a positive or negative index String slices Operations on strings: concatenation, comparison,

More information

Python for Non-programmers

Python for Non-programmers Python for Non-programmers A Gentle Introduction 2 Yann Tambouret Scientific Computing and Visualization Information Services & Technology Boston University 111 Cummington St. yannpaul@bu.edu Winter 2013

More information

UNIVERSITÀ DI PADOVA. < 2014 March >

UNIVERSITÀ DI PADOVA. < 2014 March > UNIVERSITÀ DI PADOVA < 2014 March > Easy-to-learn: Python has relatively few keywords, simple structure, and a clearly defined syntax. Easy-to-read: Python code is much more clearly defined and visible

More information

What Version Number to Install

What Version Number to Install A Python Primer This chapter provides a quick overview of the Python language. The goal in this chapter is not to teach you the Python language excellent books have been written on that subject, such as

More information

The current topic: Python. Announcements. Python. Python

The current topic: Python. Announcements. Python. Python The current topic: Python Announcements! Introduction! reasons for studying languages! language classifications! simple syntax specification Object-oriented programming: Python Types and values Syntax

More information

Basic Syntax - First Program 1

Basic Syntax - First Program 1 Python Basic Syntax Basic Syntax - First Program 1 All python files will have extension.py put the following source code in a test.py file. print "Hello, Python!";#hello world program run this program

More information

IT 374 C# and Applications/ IT695 C# Data Structures

IT 374 C# and Applications/ IT695 C# Data Structures IT 374 C# and Applications/ IT695 C# Data Structures Module 2.1: Introduction to C# App Programming Xianrong (Shawn) Zheng Spring 2017 1 Outline Introduction Creating a Simple App String Interpolation

More information

CSCE 110 Programming I

CSCE 110 Programming I CSCE 110 Programming I Basics of Python (Part 3): Functions, Lists, For Loops, and Tuples Dr. Tiffani L. Williams Department of Computer Science and Engineering Texas A&M University Spring 2014 Tiffani

More information

Fundamentals of Python: First Programs. Chapter 4: Strings and Text Files

Fundamentals of Python: First Programs. Chapter 4: Strings and Text Files Fundamentals of Python: First Programs Chapter 4: Strings and Text Files Objectives After completing this chapter, you will be able to Access individual characters in a string Retrieve a substring from

More information

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

Tools : The Java Compiler. The Java Interpreter. The Java Debugger Tools : The Java Compiler javac [ options ] filename.java... -depend: Causes recompilation of class files on which the source files given as command line arguments recursively depend. -O: Optimizes code,

More information

COMP519 Web Programming Lecture 17: Python (Part 1) Handouts

COMP519 Web Programming Lecture 17: Python (Part 1) Handouts COMP519 Web Programming Lecture 17: Python (Part 1) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Contents

More information

CMSC201 Computer Science I for Majors

CMSC201 Computer Science I for Majors CMSC201 Computer Science I for Majors Lecture 12 Tuples All materials copyright UMBC and Dr. Katherine Gibson unless otherwise noted Modularity Meaning Benefits Program design Last Class We Covered Top

More information

Key Differences Between Python and Java

Key Differences Between Python and Java Python Python supports many (but not all) aspects of object-oriented programming; but it is possible to write a Python program without making any use of OO concepts. Python is designed to be used interpretively.

More information

Lab 1: Course Intro, Getting Started with Python IDLE. Ling 1330/2330 Computational Linguistics Na-Rae Han

Lab 1: Course Intro, Getting Started with Python IDLE. Ling 1330/2330 Computational Linguistics Na-Rae Han Lab 1: Course Intro, Getting Started with Python IDLE Ling 1330/2330 Computational Linguistics Na-Rae Han Objectives Course Introduction http://www.pitt.edu/~naraehan/ling1330/index.html Student survey

More information

Script language: Python Data structures

Script language: Python Data structures Script language: Python Data structures Cédric Saule Technische Fakultät Universität Bielefeld 3. Februar 2015 Immutable vs. Mutable Previously known types: int and string. Both are Immutable but what

More information

Python 1: Intro! Max Dougherty Andrew Schmitt

Python 1: Intro! Max Dougherty Andrew Schmitt Python 1: Intro! Max Dougherty Andrew Schmitt Computational Thinking Two factors of programming: The conceptual solution to a problem. Solution syntax in a programming language BJC tries to isolate and

More information

DAVE. Language Reference Manual. Hyun Seung Hong. October 26, 2015

DAVE. Language Reference Manual. Hyun Seung Hong. October 26, 2015 DAVE Language Reference Manual Hyun Seung Hong Min Woo Kim Fan Yang Chen Yu hh2473 mk3351 fy2207 cy2415 Contents October 26, 2015 1 Introduction 3 2 Lexical Conventions 3 2.1 Character Set 3 2.2 Comment

More information

Collections. Lists, Tuples, Sets, Dictionaries

Collections. Lists, Tuples, Sets, Dictionaries Collections Lists, Tuples, Sets, Dictionaries Homework notes Homework 1 grades on canvas People mostly lost points for not reading the document carefully Didn t play again Didn t use Y/N for playing again

More information

PRG PROGRAMMING ESSENTIALS. Lecture 2 Program flow, Conditionals, Loops

PRG PROGRAMMING ESSENTIALS. Lecture 2 Program flow, Conditionals, Loops PRG PROGRAMMING ESSENTIALS 1 Lecture 2 Program flow, Conditionals, Loops https://cw.fel.cvut.cz/wiki/courses/be5b33prg/start Michal Reinštein Czech Technical University in Prague, Faculty of Electrical

More information

Introduction to Python Part 1. Brian Gregor Research Computing Services Information Services & Technology

Introduction to Python Part 1. Brian Gregor Research Computing Services Information Services & Technology Introduction to Python Part 1 Brian Gregor Research Computing Services Information Services & Technology RCS Team and Expertise Our Team Scientific Programmers Systems Administrators Graphics/Visualization

More information

CSCE 110 Programming I Basics of Python: Lists, Tuples, and Functions

CSCE 110 Programming I Basics of Python: Lists, Tuples, and Functions CSCE 110 Programming I Basics of Python: Lists, Tuples, and Functions Dr. Tiffani L. Williams Department of Computer Science and Engineering Texas A&M University Fall 2011 Lists Ordered collection of data.

More information

Computer Programming : C++

Computer Programming : C++ The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming : C++ Experiment #1 Basics Contents Structure of a program

More information

Lecture 27. Lecture 27: Regular Expressions and Python Identifiers

Lecture 27. Lecture 27: Regular Expressions and Python Identifiers Lecture 27 Lecture 27: Regular Expressions and Python Identifiers Python Syntax Python syntax makes very few restrictions on the ways that we can name our variables, functions, and classes. Variables names

More information

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners Getting Started Excerpted from Hello World! Computer Programming for Kids and Other Beginners EARLY ACCESS EDITION Warren D. Sande and Carter Sande MEAP Release: May 2008 Softbound print: November 2008

More information

Spoke. Language Reference Manual* CS4118 PROGRAMMING LANGUAGES AND TRANSLATORS. William Yang Wang, Chia-che Tsai, Zhou Yu, Xin Chen 2010/11/03

Spoke. Language Reference Manual* CS4118 PROGRAMMING LANGUAGES AND TRANSLATORS. William Yang Wang, Chia-che Tsai, Zhou Yu, Xin Chen 2010/11/03 CS4118 PROGRAMMING LANGUAGES AND TRANSLATORS Spoke Language Reference Manual* William Yang Wang, Chia-che Tsai, Zhou Yu, Xin Chen 2010/11/03 (yw2347, ct2459, zy2147, xc2180)@columbia.edu Columbia University,

More information

Babu Madhav Institute of Information Technology, UTU 2015

Babu Madhav Institute of Information Technology, UTU 2015 Five years Integrated M.Sc.(IT)(Semester 5) Question Bank 060010502:Programming in Python Unit-1:Introduction To Python Q-1 Answer the following Questions in short. 1. Which operator is used for slicing?

More information

Python - Variable Types. John R. Woodward

Python - Variable Types. John R. Woodward Python - Variable Types John R. Woodward Variables 1. Variables are nothing but named reserved memory locations to store values. This means that when you create a variable you reserve some space in memory.

More information

6.096 Introduction to C++ January (IAP) 2009

6.096 Introduction to C++ January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

More information

CIS192: Python Programming

CIS192: Python Programming CIS192: Python Programming Introduction Harry Smith University of Pennsylvania January 18, 2017 Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 1 / 34 Outline 1 Logistics Rooms

More information

The Practice of Computing Using PYTHON. Chapter 4. Working with Strings. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

The Practice of Computing Using PYTHON. Chapter 4. Working with Strings. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Practice of Computing Using PYTHON William Punch Richard Enbody Chapter 4 Working with Strings 1 Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Sequence of Characters We

More information

Data type built into Python. Dictionaries are sometimes found in other languages as associative memories or associative arrays.

Data type built into Python. Dictionaries are sometimes found in other languages as associative memories or associative arrays. NETB 329 Lecture 4 Data Structures in Python Dictionaries Data type built into Python. Dictionaries are sometimes found in other languages as associative memories or associative arrays. 1 of 70 Unlike

More information

Slicing. Open pizza_slicer.py

Slicing. Open pizza_slicer.py Slicing and Tuples Slicing Open pizza_slicer.py Indexing a string is a great way of getting to a single value in a string However, what if you want to use a section of a string Like the middle name of

More information

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on: Data and Expressions Data and Expressions Let's explore some other fundamental programming concepts Chapter 2 focuses on: Character Strings Primitive Data The Declaration And Use Of Variables Expressions

More information