Types in Scripting Languages CS 351 – Programming Paradigms.

Slides:



Advertisements
Similar presentations
Optional Static Typing Guido van Rossum (with Paul Prescod, Greg Stein, and the types-SIG)
Advertisements

Exception Handling Genome 559. Review - classes 1) Class constructors - class myClass: def __init__(self, arg1, arg2): self.var1 = arg1 self.var2 = arg2.
Object-Oriented Programming
Object-Oriented Programming Python. OO Paradigm - Review Three Characteristics of OO Languages –Inheritance It isn’t necessary to build every class from.
EECS 110: Lec 14: Classes and Objects Aleksandar Kuzmanovic Northwestern University
A Crash Course Python. Python? Isn’t that a snake? Yes, but it is also a...
OBJECT ORIENTED PROGRAMMING (OOP) IN PYTHON David Moodie.
Python: a modern hybrid A language for scripting and prototyping Balance between extensibility and powerful built-in data structures genealogy: –Setl (NYU,
Introduction to ML - Part 2 Kenny Zhu. What is next? ML has a rich set of structured values Tuples: (17, true, “stuff”) Records: {name = “george”, age.
Ruby The Gem of new programming languages. An interpreted scripting language.
Scripting languages Typically a language used for short programs to manage other programs. Interpreted, dynamically typed, permissive semantics Usually.
Functions in Python. The indentation matters… First line with less indentation is considered to be outside of the function definition. Defining Functions.
Class 24: Programming with Objects University of Virginia cs1120 David Evans.
Introduction to Python (for C++ programmers). Background Information History – created in December 1989 by Guido van Rossum Interpreted Dynamically-typed.
REFERENCES: CHAPTER 8 Object-Oriented Programming (OOP) in Python.
Python 3 Some material adapted from Upenn cis391 slides and other sources.
Python Control of Flow.
Python Crash Course Classes 3 rd year Bachelors V1.0 dd Hour 7.
Python, Part 2. Python Object Equality x == y x is y In Java: (x.equals(y)) (x == y)
1 Python Control of Flow and Defining Classes LING 5200 Computational Corpus Linguistics Martha Palmer.
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
Centre for Computer Technology ICT115 Object Oriented Design and Programming Week 2 Intro to Classes Richard Salomon and Umesh Patel Centre for Information.
Inheritance. Inhertance Inheritance is used to indicate that one class will get most or all of its features from a parent class. class Dog(Pet): Make.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
CSC1018F: Object Orientation, Exceptions and File Handling Diving into Python Ch. 5&6 Think Like a Comp. Scientist Ch
Python: Classes By Matt Wufsus. Scopes and Namespaces A namespace is a mapping from names to objects. ◦Examples: the set of built-in names, such as the.
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. Python is a high-level, interpreted, interactive and object- oriented scripting language. Python was designed to be highly readable which uses.
H3D API Training  Part 3.1: Python – Quick overview.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
CS212: Object Oriented Analysis and Design Lecture 7: Arrays, Pointers and Dynamic Memory Allocation.
Intro to Python Adriane Huber Debbie Bartlett Python Lab #1Python Lab #1 1.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
ICAPRG301A Week 2 Strings and things Charles Babbage Developed the design for the first computer which he called a difference engine, though.
CLASSES Python Workshop. Introduction  Compared with other programming languages, Python’s class mechanism adds classes with a minimum of new syntax.
+ Ruby and other programming Languages Ronald L. Ramos.
Prof. Hilfinger CS164 Lecture 51 The Pyth Language Lecture 5.
Lists, Tuples, Dictionaries, … + lots of computer work for the programmer's work! T = {'abe' :['homer','herb'], 'jackie':['marge','patty','selma'], 'homer'
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
ProgLan Python Session 4. Functions are a convenient way to divide your code into useful blocks, allowing us to: order our code, make it more readable,
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
RUBY by Ryan Chase.
Object-Oriented Programming © 2013 Goodrich, Tamassia, Goldwasser1Object-Oriented Programming.
Guide to Programming with Python Chapter Eight (Part I) Object Oriented Programming; Classes, constructors, attributes, and methods.
Python – May 19 Review –What is the difference between: list, tuple, set, dictionary? –When is it appropriate to use each? Creating our own data types:
Controlling Program Flow with Decision Structures.
CSE 130 : Winter 2009 Programming Languages Lecture 11: What’s in a Name ?
Scripting languages Originally, a scripting language, but more and more a high level programming language. Interpreted, dynamically typed, permissive semantics.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 7: Introduction to Object- Oriented Programming in Python – Exercises Xiang Lian The University of.
Machine Language Computer languages cannot be directly interpreted by the computer – they are not in binary. All commands need to be translated into binary.
Python Joseph Eckstrom, Benjamin Moore, Willis Kornegay.
Review for Test 2 Chapters 5 (start at 5.4), 6.1, , 12, 13, 15.1, Python.
ActionScript Programming Help
Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during.
Lecture VI Objects The OOP Concept Defining Classes Methods
Engineering Innovation Center
Introduction to Python
Functions and Procedures
Object Oriented Programming in Python
Python Tutorial for C Programmer Boontee Kruatrachue Kritawan Siriboon
Python Programming Language
Python Primer 1: Types and Operators
Strings and the slice operator
(more) Python.
COMPUTER PROGRAMMING SKILLS
General Computer Science for Engineers CISC 106 Lecture 03
Introduction to Object-Oriented Programming (OOP)
Introduction to Object-Oriented Programming (OOP) II
Presentation transcript:

Types in Scripting Languages CS 351 – Programming Paradigms

Data Types in Python Scripting languages don’t generally require or allow the declaration of types ofr variables. Most perform a series of run-time checks to make sure that values are used in an appropriate way. Python is strongly typed with operations enforced at run-time. The type system is Python is known as ``duck typing’’. This informally allows the type of a value to be determined via the following rule: “If looks like a duck and quacks like a duck, it is a duck”

Data Types in Python Python uses the reference model for its types. Some built-in types in Python include: TypeKindSyntax Example strString‘hello‘ listSequence[4.0, 'string', True] tupleSequence(4.0, 'string', True) setSetset([4.0, 'string', True]) dictMapping{'key1': 1.0, 'key2': False} intInteger42 floatNumber

Examples s = “hello” r = 56 l = [1,2,3] t = (56,78,54) dict = { ‘one’ : 1, ‘two’:2 } We can just initialise the types and the interpreter takes care of the rest.

Lists in Python Lists can form the basic blocks of most complex data structures in Python. l = [1,2,3,4] l.append(5) print l # prints [1,2,3,4,5] l.pop print l # prints [1,2,3,4] l.pop(0) print l # prints [2,3,4]

Lists and the filter and map functions We can define an arbitrary function def f(x): return x%2==0 filter ( f, range ( 2, 100 ) ) Defining another function: def g(x): return x+4 map ( g, range (4, 16) ) What are doing here? What paradigm is this?

Object Orientation Python is explicitly object-oriented. To define a class in Python we use the following syntax: class myclass: “This class shows Python Syntax” intval = def printsomething(self): return “hello world” We can create objects simply: x = myclass() print x.printsomething()

Object Orientation The constructor for a Python class has special syntax. class myclass: def __init__ (self, list ) : self.data = list# assign list to data x = myclass ( [1,2,3,4,5] ) print x.data# what is printed?

Object Orientation class Shape: def __init__ (self) : self.name = “Shape” def printName (self) : return self.name def getArea (self ) : return 0