Содержание
- 2. Types are determined automatically at runtime, not in response to declarations in your code Variable creation:
- 3. a = 3 Create an object to represent the value 3. Create the variable a, if
- 4. What is what? Variables are entries in a system table, with spaces for links to objects.
- 5. Types Live with Objects, Not Variables Objects have more structure than just enough space to represent
- 6. How does it work? >>> a = 3 >>> a = 'spam' >>> a = 1.23
- 7. Objects Are Garbage-Collected >>> a = 3 >>> a = 'spam‘ What happens to object 3?
- 8. Cyclic references Because references are implemented as pointers, it’s possible for an object to reference itself,
- 9. Cyclic references Old style: [1, 2, [1, 2, [1, 2, [1, 2, and so on New
- 10. Cyclic references Assignments in Python always generate references to objects, not copies of them. You can
- 11. Shared References >>> a = 3 >>> b = a names a and b are not
- 12. Shared References >>> a = 3 >>> b = a >>> a = 'spam‘
- 13. Shared References >>> a = 3 >>> b = a >>> a = a + 2
- 14. Shared References and In-Place Changes >>> L1 = [2, 3, 4] >>> L2 = L1 >>>
- 15. Avoiding side effects Side effect: L1=[24, 3, 4] and L2=[24, 3, 4] >>> L1 = [2,
- 16. Making copies Standard library copy module has a call for copying any object type generically, as
- 17. Shared References and Equality >>> L = [1, 2, 3] >>> M = L # M
- 18. Why is so? >>> L = [1, 2, 3] >>> M = [1, 2, 3] #
- 19. Summary Dynamic Typing Is Everywhere
- 20. Embedded types (reminder) The basics
- 21. Embedded types (reminder) Indexing and slicing L=[0,1,2,3] What happens when you try to index out of
- 22. Embedded types (reminder) Indexing, slicing, and del Define some list L with four items, and assign
- 23. Embedded types (reminder) Tuple assignment >>> X = 'spam' >>> Y = 'eggs' >>> X, Y
- 24. Embedded types (reminder) Dictionary keys Consider the following code fragments: >>> D = {} >>> D[1]
- 25. Embedded types (reminder) Dictionary indexing Create a dictionary named D with three entries, for keys 'a',
- 26. Embedded types (reminder) Generic operations Run interactive tests to answer the following questions: What happens when
- 27. Embedded types (reminder) String indexing Define a string S of four characters: S = "spam". Then
- 28. Embedded types (reminder) Immutable types Define a string S of four characters again: S = "spam".
- 29. Embedded types (reminder) Nesting Write a data structure that represents your personal information: name (first, middle,
- 30. Embedded types (reminder) Files Write a script that creates a new output file called myfile.txt and
- 32. Скачать презентацию