12 сентября 2019 г.

Всем привет,

Я прошу вас просмотреть мой предыдущий блог, чтобы быть в курсе моих успехов. Однако я постараюсь изо всех сил, чтобы все было просто и понятно без каких-либо предварительных исследований.

Типы данных коллекции

В языке программирования Python существует 4 типа данных коллекции, а именно:

Сегодня мы рассмотрели списки, словарь и кортежи.

Список

Список представляет собой набор, который упорядочен и может быть изменен. Это позволяет дублировать членов. Бывший.

l = ["Hello" , 23 , 4.54 , "World"] 
l = ["qwerty" , 34 , ["pot" , 'luck' , "crazy"] , "true"] 
l[0] = 'qwertry' 
l[2][1] = 'pot'
* l[::-1] : reverses the list 
* z = l.extend(p) : If l and p are two lists, z would store the list p appended to l. 
* del l[index] : Deletes the mentioned index's value 
* l.remove(value) : Removes 'value' if it is present in the list 
* value in list : returns true if value present in the list and returns false if not present 
* Similarly 'value not in list' returns true if value not present in list 
* list.append(value) : appends value to the list 
* list.index(value) : returns the index of value in the list 
* list.sort() : Sorts the list in ascending order 
* list.sort(reversed = 'True') : Sorts the list in descending order

Словарь

Словарь представляет собой неупорядоченную, изменяемую и индексируемую коллекцию. Нет повторяющихся членов. Элементы в словаре всегда хранятся в виде пар ключ-значение.

* dict[key] = value 
* dict.key() = [key1, key2, key3, ....] 
* dict.values() = [value1, value2, value3, ....]

Ex.

dict = { "python":2019 , "cpp":2011 , "c":2015 } 
dict = { "python":{"language":"high level" } , "cpp":{"language":"low level"}}
dict["cpp"]["language"] = "low level"

Кортеж

Кортеж — это упорядоченная и неизменяемая коллекция. Это позволяет дублировать членов.

* p = ('a') : defines p as a string because of only value being inputted 
* p = ('a',) : defines p as a tuple even without more than one entry
* t.item() : returns the list of items in the tuple t

Ex.

t = ('a' , 'b') 
t = ('a' , 'b' , ("Hello" , "there") )

Оставшийся тип данных коллекции set() будет рассмотрен во время следующего сеанса. Это подводит итог дневной дискуссии.

Подписание

Первоначально опубликовано на http://github.com.