Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.79 KB | None | 0 0
  1. проверьте будет ли напечатано True or False
  2. 1. a_string = ’airplane’
  3. another_string = ’airplanes’
  4. print(len(another_string) >= len(a_string))
  5. 2. print(’100’ == 100)
  6. 3. print( (100 - 7) in [5, 1, 92, 7, 17, 13])
  7. 4. a_number = 2
  8. another_number = 17
  9. print( (a_number + another_number) > 19)
  10. 5. print(not False == True)
  11. 6. print(’a’.isupper() == (not False))
  12. 7. print(sorted([2, 4, 7, 1]) == [1, 2, 4, 7])
  13. 8. a_string = ’airplane’
  14. another_string = ’airplanes’
  15. print(a_string[0] != another_string[5])
  16. 9. a_string = ’airplane’
  17. another_string = ’airplanes’
  18. print(a_string[3:] == another_string[3:8])
  19. 10. a_list = [’hello’, [’what’, ’is’], ’happening’, ’here’]
  20. appended = a_list.append(’?’)
  21. print(appended == ’?’)
  22. 11. a_dict = {’a’: [1, 2], ’b’: ’hello’}
  23. print(len(a_dict[’a’]) <= 2)
  24. 12. a_set = set([1, 4, 6, 8, 2, 3, 1, 1, 3, 5])
  25. a_set.update([1, 3, 4, 1, 1])
  26. print(len(a_set) == 7)
  27. 13. letters = [’a’,’b’,’c’,’d’]
  28. numbers = set([1, 2, 3, 4, 5])
  29. print(all([len(letters) == 4,
  30. len(numbers) != 5]))
  31. 14. a_string = ’airplane’
  32. another_string = ’airplanes’
  33. print(any([len(a_string) == 7,
  34. a_string == another_string,
  35. (2 + 17 + 2) > 21]))
  36. 15. print(all([’airplane’.startswith(’air’),
  37. ’airplane’.replace(’a’, ’b’) == ’birplbne’,
  38. ’airplane’ not in [’the airplane’, ’is in the air’]
  39. ]))
  40.  
  41. ответьте на воросы ниже.
  42. 16. что выведет len([5, 2, [1, 2], 3])?
  43. 17. объясните три способа Python’s slicing. К примеру что будет напечатано? "Bananas are yummy."[1:-1:2]
  44. 18. в чем разница между (args) (kwargs)?
  45. 19. объясните continue, break и pass statements do.
  46. 20. как простым способом рапечатать следующее построчно имя в отдельной строчке?
  47. print(" ".join(["Alan", "Maria", "Paul"]))
  48. 21. сократите выражение: a < b and c > b
  49. 22. какие два типа объектов задаются с помощью {}?
  50. 23. что такое max()? например: max([1,2,3])
  51. 24. как превратить строковой литерал в число (например ’1’) в integer?
  52. 25. как отсортировать список в обратном порядке с помощью sorted()?
  53. 26. какие встроенные функции нужо использовать для итерации по целым числам до 100?
  54. 27. какие встроенные функции нужо использовать чтобы получить справку о данной функции?
  55. как использовать *args и **kwargs in Python
  56.  
  57. найти ошибку
  58. 1 shopping_list = {"apples": 5, "bananas": 3, "pineapples": 2}
  59. 2 for product in shopping_list:
  60. 3 number = shopping_list[product]
  61. 4 print("We need " + number + " " + product)
  62.  
  63. 1 fruit = ["apple", "banana", "strawberry", "pineapple"]
  64. 2 fruit.add("mango")
  65.  
  66. 1 fruit = ["apple", "banana", "strawberry", "pineapple"]
  67. 2 fruit_string = ",".join(fruit)
  68. 3 fruit = fruit_string.split()
  69. 4 print(fruit[1])
  70.  
  71. 1 fruit1 = fruit2 = ["apple", "banana", "strawberry", "pineapple"]
  72. 2 fruit2.remove("apple")
  73. 3 print(fruit1[3])
  74.  
  75. 1 def count_items_in_list(a_list):
  76. 2 count = 0
  77. 3 for item in a_list:
  78. 4 count += 1
  79. 5 return count
  80. 6
  81. 7 fruit = ["apple", "banana", "strawberry", "pineapple"]
  82. 8 count_items_in_list(fruit)
  83. 9 print(count)
  84.  
  85. 1 number = 5
  86. 2 if number < 10:
  87. 3 print(number, "is lower than 10")
  88.  
  89.  
  90. 1 numbers = {1: "one", 2: "two", 3: "three"}
  91. 2 print(numbers["1"])
  92.  
  93.  
  94. 1 number = 5413
  95. 2 if 1 in number:
  96. 3 print("1 in", number)
  97.  
  98. что значит вызвать модуль в качестве сценария
  99.  
  100. что значит вызвать модуль с параметрами python mymod.py 50?
  101. Когда интерпретатор Python запускается с флагом -O?
  102. когда байт-код не будет записан в файл .pyc или .pyo?
  103. какова функция модуля __init__.py в пакете?
  104. что означет from пакет import *
  105. файл __init__.py в пакете содержит _all__ = ["echo", "surround", "reverse"] что это?
  106. Что делают if __name__ == “__main__”?
  107. что вернет hash(1.0) == hash(1)?
  108. что вернет[] == []? А [] is []?
  109. будут ли одинаковы id(a) id(b) при >>> a, b = 257, 257
  110. будут ли одинаковы id(a) id(b) при >>> a = 257 >>> b = 257
  111. будут ли одинаковы id(a) id(b) при >>> a = 255 >>> b = 255
  112. что вернет >>> 1 > (0 < 1) что вернет >>> 1 == (0 < 1)
  113. что вернет True + 1
  114. type([1]) type([1].append(2))
  115. a = float('inf')
  116. сколько булевых значений в [False, 1.0, "some_string", 3, True, [], False] а сколько типа int
  117. что будет напечатано
  118. t = ('one', 'two')
  119. for i in t:
  120. print(i)
  121.  
  122. t = ('one')
  123. for i in t:
  124. print(i)
  125.  
  126. t = ()
  127. print(t)
  128.  
  129. в следующем коде
  130. class Myclass
  131. pass
  132. a=Myclass()
  133. будут ли равны
  134. MyClass.__hash__(a)==a.__hash__()==hash(a)
  135.  
  136. Что вернет list(map(str.upper, ['a','d'] )) а map(str.upper, ['a','d'] ) ?
  137.  
  138. какую роль исполняет __slots__
  139.  
  140. что такое @classmethod
  141.  
  142. что такое @staticmethod
  143.  
  144. Рассмотрим следующий код
  145. class TestClass(object):
  146. @classmethod
  147. def f1(cls):
  148. print (cls.__name__)
  149.  
  150. class TestClass2(TestClass):
  151. pass
  152. что будет напечатано
  153. TestClass.f1()
  154. TestClass2.f1()
  155. a = TestClass2()
  156. a.f1()
  157.  
  158. Рассмотрим следующий код
  159. class My:
  160. num = 0
  161. def __init__(self):
  162. My.num = My.num + 1
  163. @staticmethod
  164. def showNum():
  165. print(My.num)
  166. a=My()
  167. b=My()
  168. что напечатает My.showNum()?
  169. My().showNum()
  170. а b.showNum()?
  171.  
  172. как устроены абстрактные классы в Python?
  173. как организаована сериализация и десериализация в Python?
  174.  
  175. назовите неизменяемые типы в Python?
  176. назовите изменяемые типы в Python?
  177. как задать неизменяемые типы в Python?
  178. Что делает следуюший код MyType = type('MyType', (object,), {'a': 1})?
  179. Какие типы можно исполльзовать в качестве ключей в словарях?
  180. Что означает переопределнный метод hash ?
  181. что произойдет при выполнении кода
  182. d=dict([("a",1),("a",21)])
  183. d
  184. чем отличаются встроенные методы str и repr?
  185.  
  186.  
  187.  
  188. С уважением,
  189. Youri Pomelnikov
  190. toph@mail.ru
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement