Variables and References in Python. "TAGAGAATTCTA” Objects s Names References >>> s = “TAGAGAATTCTA” >>>

Slides:



Advertisements
Similar presentations
The Important Thing About By. The Important Thing About ******** The important thing about ***** is *****. It is true s/he can *****, *****, and *****.
Advertisements

1. PROCEDURE MERGE SORT (list, first, last) If (first < last) middle = (first + last) div 2 2. Merge Sort (list, first, middle) 3. Merge Sort (list, middle+1,
PROGRAMMING In. STARTER Using the internet…Find … what does case sensitive mean what a programming language is.. 3 benefits of Python.
Container Types in Python
Chapter 6 Lists and Dictionaries CSC1310 Fall 2009.
CS 100: Roadmap to Computing Fall 2014 Lecture 0.
A Crash Course Python. Python? Isn’t that a snake? Yes, but it is also a...
Introduction to Computing Using Python Imperative Programming  Python Programs  Interactive Input/Output  One-Way and Two-Way if Statements  for Loops.
Python Dictionary.
File input and output if-then-else Genome 559: Introduction to Statistical and Computational Genomics Prof. William Stafford Noble.
1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i
©Brooks/Cole, 2001 Chapter 13 Binary Files. ©Brooks/Cole, 2001 Figure 13-1.
Structured programming
Functions. A set of statements (lines of code) that can be run repeatedly Goals: Learning Python by Lutz and Ascher –Code reuse –Procedural decomposition.
Geography 465 Assignments, Conditionals, and Loops.
Computing with Strings CSC 161: The Art of Programming Prof. Henry Kautz 9/16/2009.
Unittest in five minutes Ray Toal How to unit test Not manually, that's for sure You write code that exercises your code Perform assertions.
Recitation 1 Programming for Engineers in Python.
Lilian Blot CORE ELEMENTS COLLECTIONS & REPETITION Lecture 4 Autumn 2014 TPOP 1.
CS 100: Roadmap to Computing Fall 2014 Lecture 01.
Introduction to Computing Using Python Python  Python is an interactive language.  Java or C++: compile, run  Also, a main function or method  Python:
Chapter 4 Numbers. Python Program Structure Python programs consist of: Modules Statements Expressions Objects.
Introduction to Computing Using Python Straight-line code  In chapter 2, code was “straight-line”; the Python statements in a file (or entered into the.
Scheme & Functional Programming. ( ) >> 64 ( ) >> 666 (* ) >> 1200 (+ (* 3 5) (- 10 6)) >> 19.
Lists and the ‘ for ’ loop. Lists Lists are an ordered collection of objects >>> data = [] >>> print data [] >>> data.append("Hello!") >>> print data.
10. Python - Lists The list is a most versatile datatype available in Python, which can be written as a list of comma-separated values (items) between.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 8 Lists and Tuples.
Python Conditionals chapter 5
Python I Some material adapted from Upenn cmpe391 slides and other sources.
Strings in Python. Computers store text as strings GATTACA >>> s = "GATTACA" s Each of these are characters.
A: A: double “4” A: “34” 4.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
Dictionaries Ruth Anderson CSE 160 University of Washington 1.
The If Statement There are no switch statements in Python. You need to use just if statements. There are no switch statements in Python. You need to use.
LISTS and TUPLES. Topics Sequences Introduction to Lists List Slicing Finding Items in Lists with the in Operator List Methods and Useful Built-in Functions.
Basics Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Python focus – files The open keyword returns a file object Opening a file myFile = open('C:\file.txt', arg) Optional argument The second argument controls.
EXCEPTIONS. Catching exceptions Whenever a runtime error occurs, it create an exception object. The program stops running at this point and Python prints.
Python: File Directories What is a directory? A hierarchical file system that contains folders and files. Directory (root folder) Sub-directory (folder.
Dictionaries Ruth Anderson UW CSE 160 Winter
Introducing Python 3 Introduction to Python. Introduction to Python L1 Introducing Python 3 Learning Objectives Know what Python is and some of the applications.
Scientific Programming in Python -- Cheat Sheet
10 - Python Dictionary John R. Woodward.
Writing & reading txt files with python 3
COSC 1306 COMPUTER SCIENCE AND PROGRAMMING
Chapter 3 Instructor: Zhuojun Duan
Ruth Anderson UW CSE 160 Spring 2018
Ruth Anderson UW CSE 160 Winter 2017
Conditionals (if-then-else)
Review Operation Bingo
Ruth Anderson UW CSE 160 Winter 2017
Control flow : if statements
Lists in Python Creating lists.
Margaret Derrington KCL Easter 2014
Topics Sequences Introduction to Lists List Slicing
Goteachmaths.co.uk True or False Maze – Reverse Percentage (Calculator) Students need to find a route from the start to the finish through correctly answered.
Python I Some material adapted from Upenn cmpe391 slides and other sources.
Michael Ernst CSE 140 University of Washington
ECS15 boolean.
Appending or adding to a file using python
Lists and the ‘for’ loop
By Ryan Christen Errors and Exceptions.
Topics Sequences Introduction to Lists List Slicing
And now for something completely different . . .
Introduction to Computer Science
Training Up: Intro to Python
Variables and Equations
Virginia Lenvik Geography 375 Spring 2013
Python List.
Python Reserved Words Poster
Presentation transcript:

Variables and References in Python

"TAGAGAATTCTA” Objects s Names References >>> s = “TAGAGAATTCTA” >>>

"TAGAGAATTCTA" "GAAT" Objects s t Names References >>> s = “TAGAGAATTCTA” >>> t = “GAAT” >>>

"TAGAGAATTCTA" "GAAT" 4 Objects s t i Names References >>> s = “TAGAGAATTCTA” >>> t = “GAAT” >>> i = s.find(t) >>> print i 4 >>> Strings have a “find” method

"TAGAGAATTCTA" "GAAT" 4 Objects s t i Names References >>> s = “TAGAGAATTCTA” >>> t = “GAAT” >>> i = s.find(t) >>> print i 4 >>> t = s >>>

"TAGAGAATTCTA" 4 Objects s t i Names References >>> s = “TAGAGAATTCTA” >>> t = “GAAT” >>> i = s.find(t) >>> print i 4 >>> t = s >>>

"TAGAGAATTCTA" 4 Objects s t i Names References >>> s = “TAGAGAATTCTA” >>> t = “GAAT” >>> i = s.find(t) >>> print i 4 >>> t = s >>> a Traceback (most recent call last): File " ", line 1, in ? NameError: name 'a' is not defined >>>

"TAGAGAATTCTA" "GA" 4 Objects s t i Names References >>> s = “TAGAGAATTCTA” >>> t = “GAAT” >>> i = s.find(t) >>> print i 4 >>> t = s >>> a Traceback (most recent call last): File " ", line 1, in ? NameError: name 'a' is not defined >>> s = “GA” >>> print t TAGAGAATTCTA >>>

"GA" 4 Objects s i Names References >>> s = “TAGAGAATTCTA” >>> t = “GAAT” >>> i = s.find(t) >>> print i 4 >>> t = s >>> a Traceback (most recent call last): File " ", line 1, in ? NameError: name 'a' is not defined >>> s = “GA” >>> print t TAGAGAATTCTA >>> del t >>>

"GA" 4 Objects s i Names References >>> s = “TAGAGAATTCTA” >>> t = “GAAT” >>> i = s.find(t) >>> print i 4 >>> t = s >>> print a Traceback (most recent call last): File " ", line 1, in ? NameError: name 'a' is not defined >>> s = “GA” >>> print t TAGAGAATTCTA >>> del t >>> print t Traceback (most recent call last): File " ", line 1, in ? NameError: name 't' is not defined >>>

[2, 4] Objects L1 Names References >>> L1 = [2, 4] >>>

[2, 4, 5] Objects L1 Names References >>> L1 = [2, 4] >>> L1.append(5) >>>

[2, 4, 5] Objects L1 L2 Names References >>> L1 = [2, 4] >>> L1.append(5) >>> L2 = L1 >>>

[2, 4, 5, 7] Objects L1 L2 Names References >>> L1 = [2, 4] >>> L1.append(5) >>> L2 = L1 >>> L2.append(7) >>> print L1 [2, 4, 5, 7] >>> print L2 [2, 4, 5, 7] >>>

[2, 5, 7] Objects L1 L2 Names References >>> L1 = [2, 4] >>> L1.append(5) >>> L2 = L1 >>> L2.append(7) >>> print L1 [2, 4, 5, 7] >>> print L2 [2, 4, 5, 7] >>> del L2[1] >>>

[2, 5, 7] Objects L1 L2 Names References >>> L1 = [2, 4] >>> L1.append(5) >>> L2 = L1 >>> L2.append(7) >>> print L1 [2, 4, 5, 7] >>> print L2 [2, 4, 5, 7] >>> del L2[1] >>> L2 = L1[:] >>> L1 == L2 True >>>

[7, 5, 2] [2, 5, 7] Objects L1 L2 Names References >>> L1 = [2, 4] >>> L1.append(5) >>> L2 = L1 >>> L2.append(7) >>> print L1 [2, 4, 5, 7] >>> print L2 [2, 4, 5, 7] >>> del L2[1] >>> L2 = L1[:] >>> L1 == L2 True >>> L1.reverse() >>> L1 == L2 False >>>