Download presentation

Presentation is loading. Please wait.

Published byEmmett Gears Modified over 2 years ago

1
Variables and References in Python

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

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

4
"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

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

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

7
"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 >>>

8
"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 >>>

9
"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 >>>

10
"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 >>>

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

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

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

14
[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] >>>

15
[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] >>>

16
[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 >>>

17
[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 >>>

Similar presentations

OK

Basics Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Basics Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google