Python Pioneers: A Beginner's Guide πŸ‡ͺπŸ‡Ή
8.63K subscribers
346 photos
40 videos
24 files
64 links
Welcome to Python Pioneers: Empowering Ethiopian students to embark on their coding journey.

πŸ“’ Channel: @python_pioneers
πŸ‘₯ Group: @python_pioneers_chat
Download Telegram
What are Tuples?

Tuple α‰ python የobjects ሡα‰₯ሡα‰₯ αˆ²αˆ†αŠ• α‰£αˆˆαˆα‹ αŠ₯αŠ•α‹°α‰°αˆ›αˆ­αŠα‹ we can't change the order of the items in it.


ObjectαŠ¦α‰Ή strings, lists, tuples, integers etc. αˆŠαˆ†αŠ‘ α‹­α‰½αˆ‹αˆ‰α’

የTuple insertion characteristics preserved αŠα‹α£ once elements αŠ«αˆ΅α‰€αˆ˜αŒ₯αŠ• we can't modify them.

Elements ከtuple α‹¨αˆαŠ“αŒˆαŠ˜α‹ αˆ˜αŒ€αˆ˜αˆͺα‹« α‰£αˆ΅α‰€αˆ˜αŒ₯αŠ•α‰ α‰΅ order αŠα‹α’

Immutable: Once if we create a tuple object, then we cannot modify the content of the tuple object.

ከlist α‹¨αˆšαˆˆα‹«α‰Έα‹ ነገር α‰’αŠ–αˆ­ α‹­αˆ… αŠα‹ ፑ immutable αˆ˜αˆ†αŠ“α‰Έα‹α’


Tuple duplicate data store αˆ›αˆ¨αŒ α‹­α‰½αˆ‹αˆ unlike set.

Tuple α‰°αˆ˜αˆ³αˆ³α‹­αˆ αˆ†αŠ α‹¨α‰°αˆˆα‹«α‹¨ data type store α‹«αˆ¨αŒ‹αˆ‰ αŠ₯αŠ•α‹° list αˆ›αˆˆα‰΅ αŠα‹

to be cont'd...

#Tuple

@python_pioneers
πŸ‘4
Tuple α‹¨αˆαŠ•αˆαŒ₯αˆ­α‰£α‰Έα‹ α‰₯α‹™ αˆ˜αŠ•αŒˆα‹Άα‰½ αŠ αˆ‰ ፣ like

1. By using tuple() function
2. By manually inserting the elements inside a parenthesis

ለምሳሌ :
my_tuple = ("Monday", "Tuesday" "Wednesday")

α‹ˆα‹­αˆ range function inside tuple function α‰ αˆ˜αŒ α‰€αˆ a tuple of numbers መፍጠር αŠ₯αŠ•α‰½αˆ‹αˆˆαŠ•α’

የTuple αŒ₯α‰…αˆžα‰½ α‹αˆ΅αŒ₯ packing αŠ₯αŠ“ unpacking α‰΅αˆα‰αŠ• α‹΅αˆ­αˆ» α‹­α‹ˆαˆ΅α‹³αˆ‰α’

Packing

We can create a tuple by packing a group of variables.

Syntax :
tuple_name = elements

ለምሳሌ :
a, b, c, d = 10, 20, 30, 40
my_tuple = a, b, c, d
print(my_tuple)

#Output: (10, 20, 30, 40)

Unpacking

Tuple unpacking is the reverse process of tuple packing, we can unpack a tuple and assign its values to different variables.

Syntax :
elements = tuple_name

ለምሳሌ :
my_tuple = (10, 20, 30, 40)
a, b, c, d = my_tuple

print(" a =", a, " b =", b, " c =", c, " d =", d)

#Output : a = 10 b = 20 c = 30 d = 40

Tuple unpacking α‰ αˆ˜αŒ α‰€αˆ multiple variables α‰ αŠ αŠ•α‹΅ αŒŠα‹œ declare αˆ›α‹΅αˆ¨αŒ αŠ₯αŠ•α‰½αˆ‹αˆˆαŠ•α’


#Tuple

@python_pioneers