Introduction to VTK and Python. Filip Malmberg Uppsala universitet

Size: px
Start display at page:

Download "Introduction to VTK and Python. Filip Malmberg Uppsala universitet"

Transcription

1 Introduction to VTK and Python Filip Malmberg IT Uppsala universitet

2 Todays lecture Introduction to the Visualization Toolkit (VTK) Some words about the assignments Introduction to Python #2

3 VTK The Visualization ToolKit What is VTK? What can VTK be used for? How to actually use VTK? #3

4 VTK The Visualization ToolKit Open source, freely available software for 3D computer graphics image processing visualization Managed by Kitware, Inc. Object-oriented design (C++) O High-level of abstraction Use C++, Tcl/Tk, Python, Java #4

5 True visualization system Techniques for visualizing scalar fields vector fields tensor fields Polygon reduction Mesh smoothing Image processing Your own algorithms #5

6 Additional features Parallel support message passing multi-threading Stereo support Integrates with Motif, Qt, Tcl/Tk, Python/Tk, X11, Windows,... Event handling 3D widgets #6

7 3D graphics Surface rendering Volume rendering Ray casting T Texture mapping (2D, 3D) Lights and cameras Textures Save render window to.png,.jpg,... ((useful for movie creation) #7

8 The Visualization Pipeline DATA Visualization algorithms FILTER MAPPING Interactive feedback DISPLAY #8

9 Objects Data objects e.g. vtkpolydata, vtkimagedata Process objects Source S objects (vtkreader, vtkspheresource) F Filter objects (vtkcontourfilter) M Mapper objects (vtkpolydatamapper) #9

10 7 basic VTK objects to render a scene vtkrenderwindow: manages a window on the display device vtkrenderer: coordinates the rendering process involving lights, cameras, and actors vtklight: a source of light to illuminate the scene vtkcamera: defines the view position, focal point, etc. vtkactor: represents an object rendered in the scene, both its properties and position in the world coordinate system vtkproperty: defines the appearance properties of an actor including colour, transparency, and lighting properties such as specular and diffuse. Also representational properties like wireframe and solid surface vtkmapper: the geometric representation for an actor. More than one actor may refer to the same mapper #10

11 Cube example #11

12 User interaction vtkrenderwindowinteractor allows the user to interact with the objects Try the following key presses w wireframe mode s surface mode j joystick mode t trackball mode button1 rotate button2 translate button3 scale r reset camera view e, q exit #12

13 Sphere example #13

14 VTK and C++ Build with CMake and your favorite compiler CMake generates makefiles or project files for your environment Use the resulting file(s) to build your executable Under Windows you can use Microsoft Visual C++ 8 Express Edition You have to install Tcl and/or Python to run vtk scripts #14

15 VTK resources Download Documentation Mailing lists Links FAQ, Search VTK Textbook VTK User s guide Mastering CMake #15

16 VTK Examples Really useful for getting started Available on the VTK webpage or in the VTK folder #16

17 VTK documentation #17

18 Summary + Free and open source Create graphics/visualization applications fairly fast Object oriented - easy to derive new classes Build applications using interpreted languages Tcl, Python, and Java Many (state-of-the-art) algorithms Heavily tested in real-world applications Large user base provides decent support Commercial support and consulting available #18

19 Summary Not a super-fast graphics engine due to portability and C++ dynamic binding you need a decent workstation Very large class hierarchy learning threshold might be steep #19

20 Computer exercises 2 assignments + 1 project on VTK #20

21 Computer exercises Work in pairs Examination Give a demonstration of your program Show source code Be able to answer questions about your work #21

22 Computer exercises UpUnet account, UU-LOCAL, password C VTK is installed in G:\Program\ACGV\VTK You need to set the proper paths, run the script in a command prompt G:\Program\ACGV\set_paths.bat #22

23 #23

24 What is Python? Dynamic, interpreted high-level language. Created in 1991 by Guido van Rossum. Design philosophy: Short development time is prioritized over execution speed. Syntax similar to C++ or Java #24

25 Facts about Python Portable, available for all common platforms. Python is Open Source and free to use, even for commercial applications. (Relatively) Easy to integrate with other languages, such as Java, C/C++, Fortran and.net. Designed for multiple paradigms. Both object oriented and procedural programming are possible #25

26 What is Python good for? Internet applications, good support for HTTP, FTP, SMTP and CGI. Integrating components written in a low-level language, glue code. Portable system tools, same commands on each platform. Compare with dir (Windows) and ls (Linux). Portable GUI:s. Database handling. Projects where time of development is more important than speed of execution #26

27 What is Python not good for? Tasks where performance is critical. Such tasks can be implemented in C/C++ modules using tools such as SWIG ( #27

28 Python and VTK VTK is written in C++, but has bindings to Python, Java, Tcl... In this course, we will use VTK with Python #28

29 The Python prompt Can be used to execute individual Python commands interactively. The prompt has a memory which is kept until the prompt is closed. Start the prompt by typing python in a terminal #29

30 The Python language Variables and types Control structures Functions Classes File handling #30

31 Variables All variables in Python are references Variable Data #31

32 Variable names May contain english letters, numbers and underscores. Must not start with a number. Valid names Invalid names varname varname1 var_name_1 _var_name påskmust 1_varname varname 1 var&name #32

33 Variable assignment A reference is created with= a = 10 b = 20 c = a + b Creates the following situation: a 10 b 20 c #33

34 More on references Multiple references: Many variables can refer to the same object. list_a list_b list_c [1, 2, 3] >>> >>> >>> >>> >>> >>> [1, list = [1, 2, 3] list_a = [1, 2, 3] list_b = list_a list_c = list_b list_c[2] = 78 list_a 2, 78] Reference counting: An object is deleted automatically when no variables refer to it #34

35 Datatypes Numbers Strings Boolean types Lists Tuples Others #35

36 Numbers Different kinds of numbers are represented by different classes: I Integers (int) Big integers (long) B Real numbers (float) R Complex numbers (complex) C >>> a = 10 >>> a. class <type 'int'> >>> big_num = L >>> big_num. class <type 'long'> >>> pi_constant = >>> pi_constant. class <type 'float'> >>> z = complex(3.4, 8.35) > >>> z ( ( j) >>> z. class <type 'complex'> #36

37 Operations on numbers The operations +, -, * and / work as usual. % - Remainder // - Integer division ** - Power abs(x) a i int(x) l long(x) f float(x) ccomplex(a, b) >>> a = 3.14 >>> b = 5 >>> c = b / a >>> c. class <type 'float'> >>> 5 // 2 2 >>> 5 // float(2) > 2.0 >>> 5 / float(2) > 2.5 >>> b / complex(6, 4) > ( ( j) >>> 2 / #37

38 Strings A string is a sequence of characters. A string is created using single or double quotes. >>> s1 = "a correct example" >>> s2 = 'another correct example' >>> s3 = "not correct' File "<stdin>", line 1 s3 = "not correct' ^ SyntaxError: EOL while scanning single-quoted string >>> s4 = s1 + s2 >>> s4 'a correct exampleanother correct example' >>> s5 = str(3) > >>> s5 '3' >>> s5. class <type 'str'> #38

39 Boolean types The following expressions are false: None False The number 0 Every empty sequence Every empty mapping {} All other objects are (somewhat s simplified) defined to be true. >>> a = True >>> a. class <type 'bool'> >>> a = 5 > 7 >>> a False #39

40 Lists Lists are containers with an arbitrary number of elements. The elements can be any Python object. A single list can contain objects of many different types. >>> list = [1, 2, 3] >>> list [1, 2, 3] >>> list_2 = [1, "mixed", "li"+"st"] >>> list_2 [1, 'mixed', 'list'] #40

41 More on lists Individual element are accessed with an index within square brackets [index]. The first element has index 0. >>> list_2 [1, 'mixed', 'list'] >>> list_2[1] 'mixed' >>> list_2[1] = "New element" >>> list_2 [1, 'New element', 'list'] #41

42 Tuples Tuples are static lists. Tuples have better performance than lists, but are less flexible. > >>> tuple_1 = (1, 2, 3) >>> tuple_2 = (1, "mixed") > >>> tuple_2[1] 'mixed' >>> tuple_2[1] = "New element" Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'tuple' object does not support item assignment #42

43 Printing The Python command for writing text to the prompt is print. >>> print "Hello" Hello >>> print "Hello", "world" Hello world >>> print #43

44 If-statements >>> a = 10 >>> if a > 5:... print "The number is greater than 5"... The number is greater than 5 Note the indentation! In Python, indentation is used to control which block a statement belongs to. A colon indicates that a new block of code begins #44

45 else >>> a = 10 >>> if a < 5:... print "a is less than 5"... else:... print "a is greater than or equal to 5"... a is greater than or equal to #45

46 Multiple choices Multiple choices are handled with elif. Many languages have a case-statement for handling multiple choices. This was deemed redundant by the Python developers. >>> a = 10 >>> if a == 1:... print "a is... elif a == 2:... print "a is... elif a == 3:... print "a is... else:... print "a is... a is something else one" two" three" something else" #46

47 for-loops Again, use indentation to define a block of code. >>> for i in range(10):... print i #47

48 Nested loops >>> for i in range(2):... for j in range(3):... for k in range(4):... print "i=%i, j=%i, k=%i" % (i, j, k) p... i=0, j=0, k=0 i=0, j=0, k=1 i=0, j=0, k=2 i=0, j=0, k=3 i=0, j=1, k=0 i=0, j=1, k=1... i=1, j=1, k=2 i=1, j=1, k=3 i=1, j=2, k=0 i=1, j=2, k=1 i=1, j=2, k=2 i=1, j=2, k= #48

49 Beyond the Python prompt The python prompt is not suited for larger programs. Python programs are stored in regular text files. Commonly the filenames end with.py, but this is not required #49

50 Executing Python programs Python files are executed using the python command. The search path to this program must be set. On windows, this is set by the system variable PYTHONPATH #50

51 Python is dynamically typed # -*- coding: utf-8 -*# a refers to a number a = 10 print a, a. class # a refers to a string a = "lkshjdglgv" print a, a. class # a refers to a list a = [5, 2, 8, 5] print a, a. class a a.sort() # a refers to a number again a = 10 a a.sort() $> python dynamic_binding.py 10 <type 'int'> lkshjdglgv <type 'str'> [5, 2, 8, 5] <type 'list'> Traceback (most recent call last): File "dynamic_binding.py", line 18, in <module> a a.sort() AttributeError: 'int' object has no attribute 'sort' Duck Typing: "when I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck." #51

52 Python is strongly typed No implicit type conversions >>> a = 3 >>> b = '4' >>> a + b Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand t type(s) for +: 'int' and 'str' >>> str(a) + b '34' >>> a + int(b) > #52

53 Functions in Python A function is create using the reserved word def followed by the function name and a colon. The rules for function names are the same as for variable names. # function_01.py def function_a(): print "This is printed within function_a." $> python function_01.py This is printed first. This is printed within function_a. This is printed after the function call. print "This is printed first." function_a() # Function call print "This is printed after the function call." #53

54 Function arguments We communicate with functions by specifying arguments in the function call. # function_02.py def greeting(name, age): print """Hello %s. You are %i years old.""" % (name, age) ( g greeting("lisa", 23) greeting("erik", 31) g $> python function_02.py Hello Lisa. You are 23 years old. Hello Erik. You are 31 years old #54

55 Default arguments Default arguments can be used to avoid having to specify all arguments. # function_03.py def greeting(name, age=20): print """Hello %s. You are %i years old.""" % (name, age) ( g greeting("lisa", 23) g greeting("erik") $> python function_03.py Hello Lisa. You are 23 years old. Hello Erik. You are 20 years old #55

56 Order of arguments Problems with many arguments: Arguments must be given in the order given in the function defintion. # function_04.py def greeting(name="unknown", age=20): print """Hello %s. You are %i years old.""" % (name, a age) greeting() g g greeting("erik") greeting(45) # Gives the wrong result $> python function_04.py Hello Unknown. You are 20 years old. Hello Erik. You are 20 years old. Hello 45. You are 20 years old #56

57 Arguments by name The solution is to give arguments by name. # function_05.py def greeting(name="unknown", age=20): print """Hello %s. You are %i years old.""" % (name, age) p greeting() g greeting("erik") # Still works greeting(name="erik") # Eqvivalent greeting(age=45) # Gives the right result greeting("lisa", 33) g greeting(name = "Lisa", age = 33) # Eqvivalent $> python function_05.py Hello Unknown. You are 20 years old. Hello Erik. You are 20 years old. Hello Erik. You are 20 years old. Hello Unknown. You are 45 years old. Hello Lisa. You are 33 years old. Hello Lisa. You are 33 years old #57

58 Return values The return statement is used to return a value from a function. # return_values_01.py def my_own_join(texts, separator=" "): s = "" for text in texts: s += text + separator s = s[:-len(separator)] + "." return s my_text_pieces = ["This", "is", "not", "very", "meaningful"] print my_own_join(my_text_pieces, "_") p $> python return_values_01.py This is not very meaningful #58

59 Multiple return values Python allows any number of return values. # return_values_03.py def min_max(seq): return min(seq), max(seq) r a = [3, 573, 234, 24] minimum, maximum = min_max(a) m print minimum, maximum result = min_max(a) r print result print result. class $> python return_values_03.py (3, 573) ( <type 'tuple'> #59

60 Modules When writing larger programs, it is not practical to keep all code in the same file. In python Modules offer a way to separate large programs into smaller units. Modules are also used to organize functions and variables into namespaces #60

61 Standard modules Python has a number of standard modules that are always available for import. Modules are imported with the import-statement. >>> sys Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'sys' is not defined >>> import sys >>> sys <module 'sys' (built-in)> >>> sys.version '2.4.3 (#1, Dec , 11:39:03) \n[gcc (Red Hat )]' #61

62 3rd party modules Lots of freely available modules for: GUI:s Image Processing Computer Graphics Web development Numerical Computations #62

63 The VTK module VTK in python is implemented as a Module >>> import vtk #63

64 Object oriented programming Python is originally a procedural language, with added support for object orientation. Classes are defined using the class keyword: # -*- coding: utf-8 -*# io_01.py class MyClass MyNumer=10 def printnumber(self): print 'The number is ',MyNumber #Now we use the class a anobject=myclass() a anobject.printnumber() #64

65 Object oriented programming Python is originally a procedural language, with added support for object orientation. Classes are defined using the class keyword: # -*- coding: utf-8 -*# io_01.py class MyClass: MyNumer=10 def printnumber(self): print 'The number is ',MyNumber #Now we use the class a anobject=myclass() a anobject.printnumber() #65

66 Private variables Python has limited support for private class variables. Variable names starting with two underscores ( ) are considered private. If you really want to, it is still possible to access those variables from outside the class #66

67 File I/O in python Files are opened with the open statement # -*- coding: utf-8 -*# io_01.py f = open("newfile.txt", "r") # Open a file print f.read() # Read the whole file r -read only w - write only r+ - read and write a - append data at the end of the file b - binary file #67

68 Reading parts of a file # -*- coding: utf-8 -*# io_02.py f = open("newfile.txt") for row in f.readlines(): print row, f.close() f f = open("newfile.txt") print f.read(8) p print f.read(5) p $> python io_02.py This is line 1. This is line 2. This is line 3. This is line 4. This is line #68

69 Writing to a file # -*- coding: utf-8 -*# io_03.py f = open("newfile.txt", "w") f.write(str(3) + "\n") f f.write(str([1,2,3]) + "\n") f f.write(str({"name":"kalle"}) + "\n") f f f.close() f = open("newfile.txt", "a") f.write("this line is appended.") f f f.close() f = open("newfile.txt") print f.read() p f f.close() $> python io_03.py 3 [1, 2, 3] {'name': 'Kalle'} This line is appended #69

70 That's it! Now you know the basics of Python More info: #70

Introduction to Python Introduction to VTK. Filip Malmberg Uppsala universitet

Introduction to Python Introduction to VTK. Filip Malmberg Uppsala universitet Introduction to Python Introduction to VTK Filip Malmberg filip@cb.uu.se IT Uppsala universitet Part 1: Introduction to Python IT Uppsala universitet What is Python? Dynamic, interpreted high-level language.

More information

Introduction to Python and VTK

Introduction to Python and VTK Introduction to Python and VTK Scientific Visualization, HT 2013 Lecture 2 Johan Nysjö Centre for Image analysis Swedish University of Agricultural Sciences Uppsala University 2 About me PhD student in

More information

Introduction to Python and VTK

Introduction to Python and VTK Introduction to Python and VTK Scientific Visualization, HT 2014 Lecture 2 Johan Nysjö Centre for Image analysis Swedish University of Agricultural Sciences Uppsala University About me PhD student in Computerized

More information

Introduction to Scientific Visualization

Introduction to Scientific Visualization CS53000 - Spring 2018 Introduction to Scientific Visualization Introduction to January 11, 2018 The Visualization Toolkit Open source library for Visualization Computer Graphics Imaging Written in C++

More information

VTK: The Visualiza.on Toolkit

VTK: The Visualiza.on Toolkit VTK: The Visualiza.on Toolkit Part I: Overview and Graphics Models Han- Wei Shen The Ohio State University What is VTK? An open source, freely available soiware system for 3D graphics, image processing,

More information

Getting Started with Python

Getting Started with Python Fundamentals of Programming (Python) Getting Started with Python Sina Sajadmanesh Sharif University of Technology Some slides have been adapted from Python Programming: An Introduction to Computer Science

More information

Introduction to Python

Introduction to Python Introduction to Python CB2-101 Introduction to Scientific Computing November 11 th, 2014 Emidio Capriotti http://biofold.org/emidio Division of Informatics Department of Pathology Python Python high-level

More information

Using VTK and the OpenGL Graphics Libraries on HPCx

Using VTK and the OpenGL Graphics Libraries on HPCx Using VTK and the OpenGL Graphics Libraries on HPCx Jeremy Nowell EPCC The University of Edinburgh Edinburgh EH9 3JZ Scotland, UK April 29, 2005 Abstract Some of the graphics libraries and visualisation

More information

Visualization Toolkit (VTK) An Introduction

Visualization Toolkit (VTK) An Introduction Visualization Toolkit (VTK) An Introduction An open source, freely available software system for 3D computer graphics, image processing, and visualization Implemented as a C++ class library, with interpreted

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

Computer Graphics: Introduction to the Visualisation Toolkit

Computer Graphics: Introduction to the Visualisation Toolkit Computer Graphics: Introduction to the Visualisation Toolkit Visualisation Lecture 2 Taku Komura Institute for Perception, Action & Behaviour Taku Komura Computer Graphics & VTK 1 Last lecture... Visualisation

More information

Fundamentals of Programming (Python) Getting Started with Programming

Fundamentals of Programming (Python) Getting Started with Programming Fundamentals of Programming (Python) Getting Started with Programming Ali Taheri Sharif University of Technology Some slides have been adapted from Python Programming: An Introduction to Computer Science

More information

The Visualization Pipeline

The Visualization Pipeline The Visualization Pipeline The Visualization Pipeline 1-1 Outline Object oriented programming VTK pipeline Example 1-2 Object Oriented Programming VTK uses object oriented programming Impossible to Cover

More information

Python Programming, bridging course 2011

Python Programming, bridging course 2011 Python Programming, bridging course 2011 About the course Few lectures Focus on programming practice Slides on the homepage No course book. Using online resources instead. Online Python resources http://www.python.org/

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

Python for C programmers

Python for C programmers Python for C programmers The basics of Python are fairly simple to learn, if you already know how another structured language (like C) works. So we will walk through these basics here. This is only intended

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

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

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

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

\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

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

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

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

Scripting Languages. Python basics

Scripting Languages. Python basics Scripting Languages Python basics Interpreter Session: python Direct conversation with python (>>>) Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] on linux Type "help", "copyright",

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

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

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

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Object Oriented Programming Harry Smith University of Pennsylvania February 15, 2016 Harry Smith (University of Pennsylvania) CIS 192 Lecture 5 February 15, 2016 1 / 26 Outline

More information

Introduction to programming with Python

Introduction to programming with Python Introduction to programming with Python Ing. Lelio Campanile 1/61 Main Goal - Introduce you to programming - introduce you to the most essential feature of python programming 2/61 Before to start The name

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

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

CS 115 Lecture 8. Selection: the if statement. Neil Moore

CS 115 Lecture 8. Selection: the if statement. Neil Moore CS 115 Lecture 8 Selection: the if statement Neil Moore Department of Computer Science University of Kentucky Lexington, Kentucky 40506 neil@cs.uky.edu 24 September 2015 Selection Sometime we want to execute

More information

Programming for Engineers in Python. Autumn

Programming for Engineers in Python. Autumn Programming for Engineers in Python Autumn 2011-12 Plan Administration: Course site Homework submission guidelines Working environment Python: Variables Editor vs. shell Homework 0 Python Cont. Conditional

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Iterators, Generators, IO, and Exceptions Harry Smith University of Pennsylvania February 15, 2018 Harry Smith (University of Pennsylvania) CIS 192 Lecture 5 February 15, 2018

More information

Visualization ToolKit (VTK) Part I

Visualization ToolKit (VTK) Part I Visualization ToolKit (VTK) Part I Weiguang Guan RHPCS, ABB 131-G Email: guanw@mcmaster.ca Phone: 905-525-9140 x 22540 Outline Overview Installation Typical structure of a VTK application Visualization

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Iterators, Generators, Exceptions & IO Raymond Yin University of Pennsylvania September 28, 2016 Raymond Yin (University of Pennsylvania) CIS 192 September 28, 2016 1 / 26 Outline

More information

Introduction to Python

Introduction to Python Introduction to Python Michael Krisper Thomas Wurmitzer October 21, 2014 Michael Krisper, Thomas Wurmitzer Introduction to Python October 21, 2014 1 / 26 Schedule Tutorium I Dates & Deadlines Submission

More information

Introduction to Python

Introduction to Python Introduction to Python Reading assignment: Perkovic text, Ch. 1 and 2.1-2.5 Python Python is an interactive language. Java or C++: compile, run Also, a main function or method Python: type expressions

More information

Algorithms and Programming I. Lecture#12 Spring 2015

Algorithms and Programming I. Lecture#12 Spring 2015 Algorithms and Programming I Lecture#12 Spring 2015 Think Python How to Think Like a Computer Scientist By :Allen Downey Installing Python Follow the instructions on installing Python and IDLE on your

More information

DEBUGGING TIPS. 1 Introduction COMPUTER SCIENCE 61A

DEBUGGING TIPS. 1 Introduction COMPUTER SCIENCE 61A DEBUGGING TIPS COMPUTER SCIENCE 61A 1 Introduction Every time a function is called, Python creates what is called a stack frame for that specific function to hold local variables and other information.

More information

Visualization Toolkit(VTK) Atul Kumar MD MMST PhD IRCAD-Taiwan

Visualization Toolkit(VTK) Atul Kumar MD MMST PhD IRCAD-Taiwan Visualization Toolkit(VTK) Atul Kumar MD MMST PhD IRCAD-Taiwan Visualization What is visualization?: Informally, it is the transformation of data or information into pictures.(scientific, Data, Information)

More information

Python Input, output and variables. Lecture 23 COMPSCI111/111G SS 2018

Python Input, output and variables. Lecture 23 COMPSCI111/111G SS 2018 Python Input, output and variables Lecture 23 COMPSCI111/111G SS 2018 1 Today s lecture What is Python? Displaying text on screen using print() Variables Numbers and basic arithmetic Getting input from

More information

Python Input, output and variables

Python Input, output and variables Today s lecture Python Input, output and variables Lecture 22 COMPSCI111/111G SS 2016! What is Python?! Displaying text on screen using print()! Variables! Numbers and basic arithmetic! Getting input from

More information

Lists, loops and decisions

Lists, loops and decisions Caltech/LEAD Summer 2012 Computer Science Lecture 4: July 11, 2012 Lists, loops and decisions Lists Today Looping with the for statement Making decisions with the if statement Lists A list is a sequence

More information

Basic Concepts. Computer Science. Programming history Algorithms Pseudo code. Computer - Science Andrew Case 2

Basic Concepts. Computer Science. Programming history Algorithms Pseudo code. Computer - Science Andrew Case 2 Basic Concepts Computer Science Computer - Science - Programming history Algorithms Pseudo code 2013 Andrew Case 2 Basic Concepts Computer Science Computer a machine for performing calculations Science

More information

Here n is a variable name. The value of that variable is 176.

Here n is a variable name. The value of that variable is 176. UNIT II DATA, EXPRESSIONS, STATEMENTS 9 Python interpreter and interactive mode; values and types: int, float, boolean, string, and list; variables, expressions, statements, tuple assignment, precedence

More information

S206E Lecture 19, 5/24/2016, Python an overview

S206E Lecture 19, 5/24/2016, Python an overview S206E057 Spring 2016 Copyright 2016, Chiu-Shui Chan. All Rights Reserved. Global and local variables: differences between the two Global variable is usually declared at the start of the program, their

More information

Python for Non-programmers

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

More information

Python Input, output and variables. Lecture 22 COMPSCI111/111G SS 2016

Python Input, output and variables. Lecture 22 COMPSCI111/111G SS 2016 Python Input, output and variables Lecture 22 COMPSCI111/111G SS 2016 Today s lecture u What is Python? u Displaying text on screen using print() u Variables u Numbers and basic arithmetic u Getting input

More information

Outline. Simple types in Python Collections Processing collections Strings Tips. 1 On Python language. 2 How to use Python. 3 Syntax of Python

Outline. Simple types in Python Collections Processing collections Strings Tips. 1 On Python language. 2 How to use Python. 3 Syntax of Python Outline 1 On Python language 2 3 4 Marcin Młotkowski Object oriented programming 1 / 52 On Python language The beginnings of Pythons 90 CWI Amsterdam, Guido van Rossum Marcin Młotkowski Object oriented

More information

SOFT 161. Class Meeting 1.6

SOFT 161. Class Meeting 1.6 University of Nebraska Lincoln Class Meeting 1.6 Slide 1/13 Overview of A general purpose programming language Created by Guido van Rossum Overarching design goal was orthogonality Automatic memory management

More information

Programming for Engineers in Python. Recitation 1

Programming for Engineers in Python. Recitation 1 Programming for Engineers in Python Recitation 1 Plan Administration: Course site Homework submission guidelines Working environment Python: Variables Editor vs. shell Homework 0 Python Cont. Conditional

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

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

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

Part I. Wei Tianwen. A Brief Introduction to Python. Part I. Wei Tianwen. Basics. Object Oriented Programming

Part I. Wei Tianwen. A Brief Introduction to Python. Part I. Wei Tianwen. Basics. Object Oriented Programming 2017 Table of contents 1 2 Integers and floats Integer int and float float are elementary numeric types in. integer >>> a=1 >>> a 1 >>> type (a) Integers and floats Integer int and float

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

61A Lecture 2. Friday, August 28, 2015

61A Lecture 2. Friday, August 28, 2015 61A Lecture 2 Friday, August 28, 2015 Names, Assignment, and User-Defined Functions (Demo) Types of Expressions Primitive expressions: 2 add 'hello' Number or Numeral Name String Call expressions: max

More information

MA Petite Application

MA Petite Application MA Petite Application Carlos Grandón July 8, 2004 1 Introduction MAPA is an application for showing boxes in 2D or 3D The main object is to support visualization results from domain

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

Python Workshop. January 18, Chaitanya Talnikar. Saket Choudhary

Python Workshop. January 18, Chaitanya Talnikar. Saket Choudhary Chaitanya Talnikar Saket Choudhary January 18, 2012 Python Named after this : Python Slide 1 was a joke! Python Slide 1 was a joke! Python : Conceived in late 1980s by Guido van Rossum as a successor to

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

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

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

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

egrapher Language Reference Manual

egrapher Language Reference Manual egrapher Language Reference Manual Long Long: ll3078@columbia.edu Xinli Jia: xj2191@columbia.edu Jiefu Ying: jy2799@columbia.edu Linnan Wang: lw2645@columbia.edu Darren Chen: dsc2155@columbia.edu 1. Introduction

More information

[CHAPTER] 1 INTRODUCTION 1

[CHAPTER] 1 INTRODUCTION 1 FM_TOC C7817 47493 1/28/11 9:29 AM Page iii Table of Contents [CHAPTER] 1 INTRODUCTION 1 1.1 Two Fundamental Ideas of Computer Science: Algorithms and Information Processing...2 1.1.1 Algorithms...2 1.1.2

More information

STSCI Python Introduction. Class URL

STSCI Python Introduction. Class URL STSCI Python Introduction Class 2 Jim Hare Class URL www.pst.stsci.edu/~hare Each Class Presentation Homework suggestions Example files to download Links to sites by each class and in general I will try

More information

ECE 364 Software Engineering Tools Lab. Lecture 3 Python: Introduction

ECE 364 Software Engineering Tools Lab. Lecture 3 Python: Introduction ECE 364 Software Engineering Tools Lab Lecture 3 Python: Introduction 1 Introduction to Python Common Data Types If Statements For and While Loops Basic I/O Lecture Summary 2 What is Python? Python is

More information

Programming in Python 3

Programming in Python 3 Programming in Python 3 Programming transforms your computer from a home appliance to a power tool Al Sweigart, The invent with Python Blog Programming Introduction Write programs that solve a problem

More information

Programming to Python

Programming to Python Programming to Python Sept., 5 th Slides by M. Stepp, M. Goldstein, M. DiRamio, and S. Shah Compiling and interpreting Many languages require you to compile (translate) your program into a form that the

More information

Expressions and Variables

Expressions and Variables Expressions and Variables Expressions print(expression) An expression is evaluated to give a value. For example: 2 + 9-6 Evaluates to: 5 Data Types Integers 1, 2, 3, 42, 100, -5 Floating points 2.5, 7.0,

More information

Not-So-Mini-Lecture 6. Modules & Scripts

Not-So-Mini-Lecture 6. Modules & Scripts Not-So-Mini-Lecture 6 Modules & Scripts Interactive Shell vs. Modules Launch in command line Type each line separately Python executes as you type Write in a code editor We use Atom Editor But anything

More information

Topic 2: Introduction to Programming

Topic 2: Introduction to Programming Topic 2: Introduction to Programming 1 Textbook Strongly Recommended Exercises The Python Workbook: 12, 13, 23, and 28 Recommended Exercises The Python Workbook: 5, 7, 15, 21, 22 and 31 Recommended Reading

More information

Python in 10 (50) minutes

Python in 10 (50) minutes Python in 10 (50) minutes https://www.stavros.io/tutorials/python/ Python for Microcontrollers Getting started with MicroPython Donald Norris, McGrawHill (2017) Python is strongly typed (i.e. types are

More information

Python. Executive Summary

Python. Executive Summary Python Executive Summary DEFINITIONS OBJECT: a unit of data of a particular type with characteristic functionality (i.e., methods and/or response to operators). Everything in Python is an object. "atomic"

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

Computer Components. Software{ User Programs. Operating System. Hardware

Computer Components. Software{ User Programs. Operating System. Hardware Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

More information

At full speed with Python

At full speed with Python At full speed with Python João Ventura v0.1 Contents 1 Introduction 2 2 Installation 3 2.1 Installing on Windows............................ 3 2.2 Installing on macos............................. 5 2.3

More information

CS Programming Languages: Python

CS Programming Languages: Python CS 3101-1 - Programming Languages: Python Lecture 5: Exceptions / Daniel Bauer (bauer@cs.columbia.edu) October 08 2014 Daniel Bauer CS3101-1 Python - 05 - Exceptions / 1/35 Contents Exceptions Daniel Bauer

More information

STATS 507 Data Analysis in Python. Lecture 2: Functions, Conditionals, Recursion and Iteration

STATS 507 Data Analysis in Python. Lecture 2: Functions, Conditionals, Recursion and Iteration STATS 507 Data Analysis in Python Lecture 2: Functions, Conditionals, Recursion and Iteration Functions in Python We ve already seen examples of functions: e.g., type()and print() Function calls take the

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

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

Python. Karin Lagesen.

Python. Karin Lagesen. Python Karin Lagesen karin.lagesen@bio.uio.no Plan for the day Basic data types data manipulation Flow control and file handling Functions Biopython package What is programming? Programming: ordered set

More information

MEIN 50010: Python Flow Control

MEIN 50010: Python Flow Control : Python Fabian Sievers Higgins Lab, Conway Institute University College Dublin Wednesday, 2017-10-11 Program Overview Program Code Block Statements Expressions Expressions & Statements An expression has

More information

python 01 September 16, 2016

python 01 September 16, 2016 python 01 September 16, 2016 1 Introduction to Python adapted from Steve Phelps lectures - (http://sphelps.net) 2 Python is interpreted Python is an interpreted language (Java and C are not). In [1]: 7

More information

Introduction to Python. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas

Introduction to Python. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas Introduction to Python Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas If you have your own PC, download and install a syntax-highlighting text editor and Python

More information

Introduction to Python

Introduction to Python Introduction to Python EECS 4415 Big Data Systems Tilemachos Pechlivanoglou tipech@eecs.yorku.ca 2 Background Why Python? "Scripting language" Very easy to learn Interactive front-end for C/C++ code Object-oriented

More information

Python Tutorial. Day 2

Python Tutorial. Day 2 Python Tutorial Day 2 1 Control: Whitespace in perl and C, blocking is controlled by curly-braces in shell, by matching block delimiters, if...then...fi in Python, blocking is controlled by indentation

More information

MEIN 50010: Python Introduction

MEIN 50010: Python Introduction : Python Fabian Sievers Higgins Lab, Conway Institute University College Dublin Wednesday, 2017-10-04 Outline Goals Teach basic programming concepts Apply these concepts using Python Use Python Packages

More information

LECTURE 4 Python Basics Part 3

LECTURE 4 Python Basics Part 3 LECTURE 4 Python Basics Part 3 INPUT We ve already seen two useful functions for grabbing input from a user: raw_input() Asks the user for a string of input, and returns the string. If you provide an argument,

More information

cs1114 REVIEW of details test closed laptop period

cs1114 REVIEW of details test closed laptop period python details DOES NOT COVER FUNCTIONS!!! This is a sample of some of the things that you are responsible for do not believe that if you know only the things on this test that they will get an A on any

More information

Shell / Python Tutorial. CS279 Autumn 2017 Rishi Bedi

Shell / Python Tutorial. CS279 Autumn 2017 Rishi Bedi Shell / Python Tutorial CS279 Autumn 2017 Rishi Bedi Shell (== console, == terminal, == command prompt) You might also hear it called bash, which is the most widely used shell program macos Windows 10+

More information

Advanced Python. Executive Summary, Session 1

Advanced Python. Executive Summary, Session 1 Advanced Python Executive Summary, Session 1 OBJECT: a unit of data of a particular type with characteristic functionality (i.e., methods and/or use with operators). Everything in Python is an object.

More information

Python. Tutorial Lecture for EE562 Artificial Intelligence for Engineers

Python. Tutorial Lecture for EE562 Artificial Intelligence for Engineers Python Tutorial Lecture for EE562 Artificial Intelligence for Engineers 1 Why Python for AI? For many years, we used Lisp, because it handled lists and trees really well, had garbage collection, and didn

More information

Introduction to computers and Python. Matthieu Choplin

Introduction to computers and Python. Matthieu Choplin Introduction to computers and Python Matthieu Choplin matthieu.choplin@city.ac.uk http://moodle.city.ac.uk/ 1 Objectives To get a brief overview of what Python is To understand computer basics and programs

More information

3. Java - Language Constructs I

3. Java - Language Constructs I Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks

More information

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications Hello World! Computer Programming for Kids and Other Beginners by Warren Sande and Carter Sande Chapter 1 Copyright 2009 Manning Publications brief contents Preface xiii Acknowledgments xix About this

More information

Getting Started Values, Expressions, and Statements CS GMU

Getting Started Values, Expressions, and Statements CS GMU Getting Started Values, Expressions, and Statements CS 112 @ GMU Topics where does code go? values and expressions variables and assignment 2 where does code go? we can use the interactive Python interpreter

More information