Telegram Group & Telegram Channel
Python dasturlash maktabi
Kortej.png
Ⓜ️ Kortejlar (tuple)

# Kortejlar bir nechta ob’yektlarni birgalikda saqlashga xizmat qiladi.

# tuple() funksiyasi, oddiy qavs yoki qavs ochmasdan kortejlarni tuzish mumkin.

tuple_funksiyasi = tuple(['mandarin', 'ananas'])
print(tuple_funksiyasi) # ('mandarin', 'ananas')

qavsli = ('nok', 'shaftoli')
print(qavsli) # ('nok', 'shaftoli')

qavssiz = 'olma', 'anor', 'kadi'
print(qavssiz) # ('olma', 'anor', 'kadi')

# Kortej elementlar orasini vergul bilan ajratish orqali hosil qilinadi.
var1 = ('@pythonuz')
print(type(var1)) # <class 'str'>

var2 = ('@pythonuz',)
print(type(var2)) # <class 'tuple'>


# Kortejning afzalliklari.
1) Kortej o`zgartirishlardan himoyalangan bo`ladi.

# Ro'yxatlarni o'zgartirish mumkin.
royxat = ['@pythonuz', '@phpuz']
royxat[1] = 'js_uz'
print(royxat) # ['@pythonuz', 'js_uz']

# Kortejni ro'yxatdan asosiy farqi korjejlarni o'zgartirib bo'lmaydi.
kortej = ('olma', 'anor')
kortej[1] = 'gilos'
print(kortej) # TypeError: 'tuple' object does not support item assignment

Kortej imkoniyatlari.

# 1) Kortejni ro'yxat turiga o'girib so'ng o'zgartirish kiritish mumkin.
kortej = ('olma', 'anor')
kortejdan_royxatga = list(kortej)
kortejdan_royxatga[1] = 'gilos'
print(kortejdan_royxatga) # ['olma', 'gilos']
royxatdan_kortejga = tuple(kortejdan_royxatga)
print(royxatdan_kortejga) # ('olma', 'gilos')

# 2) Kortej xotiradan kichik hajm band qiladi.

import sys
kortej = ('olma', 1, True)
print(sys.getsizeof(kortej)) # 64
royxat = ['gilos', 0, False]
print(sys.getsizeof(royxat)) # 80

# 3) Kortejdan lug`at kaliti sifatida foydalanish mumkin.

kortej = {(1, True, 'olma'): 7} 
print(kortej[(1, True, 'olma')]) # 7
royxat= {[1, True, 'olma']: 7}
print(royxat[[1, True, 'olma']]) # TypeError: unhashable type: 'list'

# Kvadrat qavs ichidagi indeks raqamiga murojaat qilib kortej elementlarini tanlashingiz mumkin.

kortej = ('olma', 'uzum', 'gilos', 'behi', 'anor', "o'rik", 'apelsin', 'shaftoli', 'ananas', 'nok')

# Kortejdagi ikkinchi elelmentni chop qiling
print(kortej[1])  # uzum
# Kortejdagi oxirgi elelmentni chop qiling
print(kortej[-1])  # nok
# Kortejdagi to'rtinchi elelmentdan oltinchi elelmentgacha chop qiling
print(kortej[3:6])  # ('behi', 'anor', "o'rik")
# Kortejdagi beshinchi elelmentgacha chop qiling
print(kortej[:4])  # ('olma', 'uzum', 'gilos', 'behi')
# Kortejdagi iikinchi elelmentdan oxirgi elelmentgacha chop qiling
print(kortej[1:])  # ('uzum', 'gilos', 'behi', 'anor', "o'rik", 'apelsin', 'shaftoli', 'ananas', 'nok')

# Kortejalrni birlashtirish.

tuple1 = ("a", "b" , "c")
tuple2 = (1, 2, 3)
tuple3 = tuple1 + tuple2
print(tuple3) # ('a', 'b', 'c', 1, 2, 3)

# Kortejlarni ko'paytirish.
mevalar = ("olma", "banan")
kortej = mevalar * 2
print(kortej) # ('olma', 'banan', 'olma', 'banan')

Kortejda namedtuple subklasidan foydalanish.

@pythonuz



tg-me.com/pythonuz/416
Create:
Last Update:

Ⓜ️ Kortejlar (tuple)

# Kortejlar bir nechta ob’yektlarni birgalikda saqlashga xizmat qiladi.

# tuple() funksiyasi, oddiy qavs yoki qavs ochmasdan kortejlarni tuzish mumkin.

tuple_funksiyasi = tuple(['mandarin', 'ananas'])
print(tuple_funksiyasi) # ('mandarin', 'ananas')

qavsli = ('nok', 'shaftoli')
print(qavsli) # ('nok', 'shaftoli')

qavssiz = 'olma', 'anor', 'kadi'
print(qavssiz) # ('olma', 'anor', 'kadi')

# Kortej elementlar orasini vergul bilan ajratish orqali hosil qilinadi.
var1 = ('@pythonuz')
print(type(var1)) # <class 'str'>

var2 = ('@pythonuz',)
print(type(var2)) # <class 'tuple'>


# Kortejning afzalliklari.
1) Kortej o`zgartirishlardan himoyalangan bo`ladi.

# Ro'yxatlarni o'zgartirish mumkin.
royxat = ['@pythonuz', '@phpuz']
royxat[1] = 'js_uz'
print(royxat) # ['@pythonuz', 'js_uz']

# Kortejni ro'yxatdan asosiy farqi korjejlarni o'zgartirib bo'lmaydi.
kortej = ('olma', 'anor')
kortej[1] = 'gilos'
print(kortej) # TypeError: 'tuple' object does not support item assignment

Kortej imkoniyatlari.

# 1) Kortejni ro'yxat turiga o'girib so'ng o'zgartirish kiritish mumkin.
kortej = ('olma', 'anor')
kortejdan_royxatga = list(kortej)
kortejdan_royxatga[1] = 'gilos'
print(kortejdan_royxatga) # ['olma', 'gilos']
royxatdan_kortejga = tuple(kortejdan_royxatga)
print(royxatdan_kortejga) # ('olma', 'gilos')

# 2) Kortej xotiradan kichik hajm band qiladi.

import sys
kortej = ('olma', 1, True)
print(sys.getsizeof(kortej)) # 64
royxat = ['gilos', 0, False]
print(sys.getsizeof(royxat)) # 80

# 3) Kortejdan lug`at kaliti sifatida foydalanish mumkin.

kortej = {(1, True, 'olma'): 7} 
print(kortej[(1, True, 'olma')]) # 7
royxat= {[1, True, 'olma']: 7}
print(royxat[[1, True, 'olma']]) # TypeError: unhashable type: 'list'

# Kvadrat qavs ichidagi indeks raqamiga murojaat qilib kortej elementlarini tanlashingiz mumkin.

kortej = ('olma', 'uzum', 'gilos', 'behi', 'anor', "o'rik", 'apelsin', 'shaftoli', 'ananas', 'nok')

# Kortejdagi ikkinchi elelmentni chop qiling
print(kortej[1])  # uzum
# Kortejdagi oxirgi elelmentni chop qiling
print(kortej[-1])  # nok
# Kortejdagi to'rtinchi elelmentdan oltinchi elelmentgacha chop qiling
print(kortej[3:6])  # ('behi', 'anor', "o'rik")
# Kortejdagi beshinchi elelmentgacha chop qiling
print(kortej[:4])  # ('olma', 'uzum', 'gilos', 'behi')
# Kortejdagi iikinchi elelmentdan oxirgi elelmentgacha chop qiling
print(kortej[1:])  # ('uzum', 'gilos', 'behi', 'anor', "o'rik", 'apelsin', 'shaftoli', 'ananas', 'nok')

# Kortejalrni birlashtirish.

tuple1 = ("a", "b" , "c")
tuple2 = (1, 2, 3)
tuple3 = tuple1 + tuple2
print(tuple3) # ('a', 'b', 'c', 1, 2, 3)

# Kortejlarni ko'paytirish.
mevalar = ("olma", "banan")
kortej = mevalar * 2
print(kortej) # ('olma', 'banan', 'olma', 'banan')

Kortejda namedtuple subklasidan foydalanish.

@pythonuz

BY Python dasturlash maktabi


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/pythonuz/416

View MORE
Open in Telegram


Python dasturlash maktabi Telegram | DID YOU KNOW?

Date: |

Look for Channels Online

You guessed it – the internet is your friend. A good place to start looking for Telegram channels is Reddit. This is one of the biggest sites on the internet, with millions of communities, including those from Telegram.Then, you can search one of the many dedicated websites for Telegram channel searching. One of them is telegram-group.com. This website has many categories and a really simple user interface. Another great site is telegram channels.me. It has even more channels than the previous one, and an even better user experience.These are just some of the many available websites. You can look them up online if you’re not satisfied with these two. All of these sites list only public channels. If you want to join a private channel, you’ll have to ask one of its members to invite you.

Unlimited members in Telegram group now

Telegram has made it easier for its users to communicate, as it has introduced a feature that allows more than 200,000 users in a group chat. However, if the users in a group chat move past 200,000, it changes into "Broadcast Group", but the feature comes with a restriction. Groups with close to 200k members can be converted to a Broadcast Group that allows unlimited members. Only admins can post in Broadcast Groups, but everyone can read along and participate in group Voice Chats," Telegram added.

Python dasturlash maktabi from us


Telegram Python dasturlash maktabi
FROM USA