Professional IronPython



Download 20,35 Mb.
Pdf ko'rish
bet82/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   78   79   80   81   82   83   84   85   ...   453
lISTINg 4-5: 
 Accessing specific array elements
# Create the array.
continues
548592c04.indd 61
2/24/10 12:47:35 PM
www.finebook.ir


62

CHAPTER 4
Using ArrAys And ColleCtions
MyList = [1, 2, 3, 4, 5, 6]
# Access every other element.
for Output in MyList[::2]:
print Output
FIguRE 4-4: 
You can use complex expressions to create arrays.
The output is 1, 3, and 5 for this example. Actually, you can provide more than the step for the 
output. IronPython provides the means to provide start:stop:step with the colons. For example, if 
you wanted to start with element 1 instead of element 0, you’d type:
for Output in MyList[1::2]:
print Output
This code outputs 2, 4, and 6 based on the previous input. You can control things even more. For 
example, look at the following code.
for Output in MyList[1:4:2]:
print Output
Run this code and you’ll see 2 and 4 as output. The code begins with element 1, stops with element 4, 
and uses a step of 2.
Let’s look at one other interesting IronPython array technique. Listing 4-6 shows code that not only 
shows the array items, but also the index associated with that item.
lISTINg 4-6: 
 Looping through array elements
# Create the array.
MyList = [‘Zero’, ‘One’, ‘Two’, ‘Three’, ‘Four’]
# Display the items and their index.
for index, item in enumerate(MyList):
print index, item
# Pause after the debug session.
raw_input(‘Press any key to continue...’)
lISTINg 4-5 
(continued)
548592c04.indd 62
2/24/10 12:47:35 PM
www.finebook.ir


Working with Tuples, Lists, and Arrays

Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   78   79   80   81   82   83   84   85   ...   453




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