-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
186 lines (160 loc) · 3.57 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# УСЛОВНЫЕ ОПЕРАТОРЫ:
# user_data = int(input("Введите число: "))
# isHappy = True
# if not isHappy:
# print("I'am happy")
# elif user_data == 5:
# print("Good job!")
# else:
# print("User is unhappy")
# Тернарный оператор:
# data = input()
#
# number = 5 if data == "Five" else 0
# if data == "Five":
# number = 5
# else:
# number = 0
# print(number)
# ЦИКЛЫ И ОПЕРАТОРЫ:
# for i in range(6):
# print(i)
# count = 0
# word = "Hi, Sergei!"
# for i in word:
# if i == "i":
# count += 1
#
# print(count)
# for i in range(1, 11):
# if i == 5:
# break
# print(i)
# found = None
# for i in "Hello":
# if i == "l":
# found = True
# break
# else:
# found = False
# print(found)
# СПИСКИ, ФУНКЦИИ и их МЕТОДЫ:
# nums = [2, 10, 7, True, "Hello, Python!", 9.33, [5, 99]]
#
# nums[1] = 27
# nums[4] = False
#
# print(nums[-1][1])
# numbers = [3, 5, 10]
#
# numbers.append(100)
# numbers.insert(1, True)
#
# b = [3, 77, 9]
# numbers.extend(b)
# numbers.sort()
# numbers.reverse()
#
# numbers.pop(0)
# numbers.remove(77)
#
# #numbers.clear()
#
# #print(numbers.count(9))
# print(len(numbers))
# nums = [3, 10, 9, "50", False]
#
# for el in nums:
# el *= 2
# print(el)
# n = int(input("Enter lenth: "))
# i = 0
# user_list = []
#
# while i < n:
# string = "Enter element #" + str(i + 1) + ": "
# user_list.append(input(string))
# i += 1
#
# print(user_list)
# ФУНКЦИИ СТРОК.Индексы и срезы:
# word = "Football,basketball,skate"
# # print(word.count('r'))
# # print(word.capitalize())
# # print(word.upper())
# # print(word[2])
# # print(len(word))
# # print(word.find('pr'))
# hobby = word.split(',')
# # print(hobby[1])
#
# for i in range(len(hobby)):
# hobby[i] = hobby[i].capitalize()
#
# result = ",".join(hobby)
# print(result)
# word = 'Football'
#
# # print(word[0:4])
# # print(word[4:6])
# # print(word[4:])
# print(word[1:-1:2])
# list = [1,15,'bug', True, 7.22]
#
# print(list[2:5:2])
# print(list[::-1])
# КОРТЕЖИ (TUPLE):
# кортежи в отличии от списков нельзя изменять, удалять или добавлять элемнты
# data = (3,5,9,True, 7.33, "Hi!")
# print(data[2:5])
#
# print(data.count(50))
# print(len(data))
# data = (3,5,9,True, 7.33, "Hi!")
#
# for i in data:
# print(i)
# nums = [5,7,8]
# new_data = tuple(nums)
# print(new_data)
# СЛОВАРИ (dict):
# country = {'code': 'US', 'name': 'United States'}
# country = dict(code='US', name='United States')
# print(country)
#
# for key,value in country.items():
# print(key, '-', value)
# print(country.get('name'))
# country.clear()
# country.pop('name')
# country.popitem()
# print(country)
# person = {
# 'user_1': {
# 'first_name': 'John',
# 'last_name': 'Bon Jovi',
# 'age': 38,
# 'address': ('Samara city', 'Sugar street', '77')
# },
# 'user_2': {
#
# }
# }
#
# print(person['user_1']['address'][1])
# МНОЖЕСТВА (set and frozenset):
# data = set("hello")
# print(data)
# выводятся в случайном порядке и все повторяющиеся элементы удаляются
# data = {1,4,9,3,3}
# data.add(48)
# data.update([32, True, 8, 0])
# data.remove(0)
# data.pop()
# print(data)
# во множествах нельзя изменять элементы
# nums = [5,7,3,5,5]
# new_nums = set(nums)
# print(new_nums)
new_data = frozenset([3,77,8,0,True, False, "Hello",1,33,0])
print(new_data)