Python Projects for Beginners a ten-Week Bootcamp Approach to Python Programming
Python Projects for Beginners A Ten Week Bootcamp Approach to Python
Today was important in understanding how to work with dictionaries. remember that adding and altering key-value pairs are the same syntax. Wednesday: Tuples, Sets, Frozensets Python includes several other data collections that all have their own features. Today, we’ll look at another three that can be useful at times. To follow along with this lesson, let’s continue from our notebook file “Week_06” and simply add a markdown cell at the bottom that says, “Tuples, Sets, Frozensets.” What Are Tuples? A tuple is identical to a list, except it is immutable. When something is immutable, it means that it cannot be altered once declared. Tuples are useful for storing information that you don’t want to change. They’re ordered like lists, so you can iterate through them using an index. Declaring a TupleTo declare a tuple, you use a comma to separate two or more items. Lists are denoted by their square brackets on the outside, whereas tuples can be declared with optional parenthesis. It’s more likely they’re declared with parenthesis as it’s easier to read. Let’s see an example: # declaring a tuple t1 = ("hello", 2, "hello") # with parens t2 = True, 1 # without parens print( type(t1), type(t2) ) # both are tuples t1[0] = 1 # will crash, tuples are immutable once declared Go ahead and run the cell. You can see that we output the types of our variables, which both output “tuple”. As stated, tuples are declared with and without parenthesis. The last line in this cell will create an error because a tuple’s items cannot be altered once declared. The only way to overwrite the data within a tuple is to re-declare the entire tuple. Download 2,61 Mb. Do'stlaringiz bilan baham: Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024 ma'muriyatiga murojaat qiling |
kiriting | ro'yxatdan o'tish Bosh sahifa юртда тантана Боғда битган Бугун юртда Эшитганлар жилманглар Эшитмадим деманглар битган бодомлар Yangiariq tumani qitish marakazi Raqamli texnologiyalar ilishida muhokamadan tasdiqqa tavsiya tavsiya etilgan iqtisodiyot kafedrasi steiermarkischen landesregierung asarlaringizni yuboring o'zingizning asarlaringizni Iltimos faqat faqat o'zingizning steierm rkischen landesregierung fachabteilung rkischen landesregierung hamshira loyihasi loyihasi mavsum faolyatining oqibatlari asosiy adabiyotlar fakulteti ahborot ahborot havfsizligi havfsizligi kafedrasi fanidan bo’yicha fakulteti iqtisodiyot boshqaruv fakulteti chiqarishda boshqaruv ishlab chiqarishda iqtisodiyot fakultet multiservis tarmoqlari fanidan asosiy Uzbek fanidan mavzulari potok asosidagi multiservis 'aliyyil a'ziym billahil 'aliyyil illaa billahil quvvata illaa falah' deganida Kompyuter savodxonligi bo’yicha mustaqil 'alal falah' Hayya 'alal 'alas soloh Hayya 'alas mavsum boyicha yuklab olish |