Учебники 📚 » Презентации » Другие презентации » Презентация по Программированию на тему "Python Tuples" в рамках Исследования в действии

Презентация по Программированию на тему "Python Tuples" в рамках Исследования в действии

Презентация по Программированию на тему "Python Tuples" в рамках Исследования в действии - Класс учебник | Академический школьный учебник скачать | Сайт школьных книг учебников uchebniki.org.ua
Смотреть онлайн
Поделиться с друзьями:
Презентация по Программированию на тему "Python Tuples" в рамках Исследования в действии:
Cкачать презентацию: Презентация по Программированию на тему "Python Tuples" в рамках Исследования в действии

Презентация для классов "Презентация по Программированию на тему "Python Tuples" в рамках Исследования в действии" онлайн бесплатно на сайте электронных школьных презентаций uchebniki.org.ua

Tuples<br>Unit 11.2А: Data structures<br>
1 слайд

Tuples
Unit 11.2А: Data structures

Lesson objectives<br>11.2.4.1 create a tuple;<br>11.2.2.1 perform access to the elements of strings,
2 слайд

Lesson objectives
11.2.4.1 create a tuple;
11.2.2.1 perform access to the elements of strings, lists, tuples;
11.2.4.2 convert from one data structure to another;
11.4.3.2 solve applied problems of various subject areas.

3 слайд

Python Tuple Quiz<br>https://pynative.com/python-tuple-quiz/<br>
4 слайд

Python Tuple Quiz
https://pynative.com/python-tuple-quiz/

https://holypython.com/beginner-python-exercises/exercise-7-python-tuples/<br>Python Tuple Exercises
5 слайд

https://holypython.com/beginner-python-exercises/exercise-7-python-tuples/
Python Tuple Exercises

Task<br>Create a Num Tuple<br>Create a mixed Tuple<br>Find the maximum, minimum and sum of Num tuple
6 слайд

Task
Create a Num Tuple
Create a mixed Tuple
Find the maximum, minimum and sum of Num tuple
Zipped two Tuples
Add “5” element to the Num Tuple and Output it.
[5]
2. Python program to remove all tuples of length K
Input: [(1, 4), (2), (4,5,6,8), (26), (3, 0, 1), (4)]
Output: [(1, 4), (4, 5, 6, 8), (3, 0, 1)]
k = 1

Python program to remove all tuples of length K<br>Write a <br>Input: [(1, 4), (2), (4,5,6,8), (26),
7 слайд

Python program to remove all tuples of length K
Write a
Input: [(1, 4), (2), (4,5,6,8), (26), (3, 0, 1), (4)]
Output: [(1, 4), (4, 5, 6, 8), (3, 0, 1)]
k = 1

Tuples<br>A tuple is a collection of objects which is ordered and immutable. Tuples are similar to l
8 слайд

Tuples
A tuple is a collection of objects which is ordered and immutable. Tuples are similar to lists, the main difference list the immutability.
In Python tuples are written with round brackets and comma separated values.

Tuples<br>A tuple is a collection of objects which is ordered and immutable. Tuples are similar to l
9 слайд

Tuples
A tuple is a collection of objects which is ordered and immutable. Tuples are similar to lists, the main difference list the immutability.
In Python tuples are written with round brackets and comma separated values.

my_tuple = ("Max", 28, "New York")

Reasons to use a tuple over a list<br>Generally used for objects that belong together.<br>Use tuple
10 слайд

Reasons to use a tuple over a list
Generally used for objects that belong together.
Use tuple for heterogeneous (different) data types and list for homogeneous (similar) data types.
Since tuple are immutable, iterating through tuple is slightly faster than with list.
Tuples with their immutable elements can be used as key for a dictionary.
This is not possible with lists.
If you have data that doesn't change, implementing it as tuple will guarantee that it remains write-protected.

Create a tuple<br>tuple_1 = ("Max", 28, "New York")<br>tuple_2 = "Linda&quo
11 слайд

Create a tuple
tuple_1 = ("Max", 28, "New York")
tuple_2 = "Linda", 25, "Miami"
tuple_3=(25,)
print(tuple_1)
print(tuple_2)
print(tuple_3)
tuple_4 = tuple([1,2,3])
print(tuple_4)

Access elements<br>tuple_1 = ("Max", 28, "New York")<br>item = tuple_1[0]<br>pri
12 слайд

Access elements
tuple_1 = ("Max", 28, "New York")
item = tuple_1[0]
print(item)
item = tuple_1[-1]
print(item)
item = tuple_1[2]
print(item)

Add or change items<br>tuple_1 = ("Max", 28, "New York")<br>tuple_1[2] = "B
13 слайд

Add or change items
tuple_1 = ("Max", 28, "New York")
tuple_1[2] = "Boston“
print(tuple_1)
Not possible and will raise a TypeError.

Iterating<br>tuple_1 = ("Max", 28, "New York")<br>for i in tuple_1: <br>    prin
14 слайд

Iterating
tuple_1 = ("Max", 28, "New York")
for i in tuple_1:
print(i)

Check if an item exists<br>tuple_1 = ("Max", 28, "New York")<br>if "New Yor
15 слайд

Check if an item exists
tuple_1 = ("Max", 28, "New York")
if "New York" in tuple_1:
print("yes")
else:
print("no")

Useful methods<br>my_tuple = ('a','p','p','l','e',
16 слайд

Useful methods
my_tuple = ('a','p','p','l','e',)
# len() : get the number of elements in a tuple
print(len(my_tuple))
# count(x) : Return the number of items that is equal to x
print(my_tuple.count('p'))
# index(x) : Return index of first item that is equal to x
print(my_tuple.index('l'))
# repetition
my_tuple = ('a', 'b') * 5
print(my_tuple)

Useful methods<br># concatenation<br>my_tuple = (1,2,3) + (4,5,6)<br>print(my_tuple)<br># convert li
17 слайд

Useful methods
# concatenation
my_tuple = (1,2,3) + (4,5,6)
print(my_tuple)
# convert list to a tuple and vice versa
my_list = ['a', 'b', 'c', 'd']
list_to_tuple = tuple(my_list)
print(list_to_tuple)
tuple_to_list = list(list_to_tuple)
print(tuple_to_list)
# convert string to tuple
string_to_tuple = tuple('Hello')
print(string_to_tuple)

Slicing<br>a = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)<br>b = a[1:3] # Note that the last index is not inclu
18 слайд

Slicing
a = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
b = a[1:3] # Note that the last index is not included
print(b)
b = a[2:] # until the end
print(b)
b = a[:3] # from beginning
print(b)
b = a[::2] # start to end with every second item
print(b)
b = a[::-1] # reverse tuple
print(b)

Отзывы на uchebniki.org.ua "Презентация по Программированию на тему "Python Tuples" в рамках Исследования в действии" (0)
Оставить отзыв
Прокомментировать
Регистрация
Вход
Авторизация