亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? python for newbies.htm

?? a collection of mega hacking tools
?? HTM
?? 第 1 頁 / 共 4 頁
字號:
like it. The next line has a cryptic-looking statement elif. First notice it's 

not indented; it's not in the same code block. elif is not life backwards, it's 

short for else if. If the first condition isn't true, it checks the next one. 

Next block, there we go. Finally comes else: the fallback statement, in case 

none of the above conditions (there can be as many as you want, which serves as 

a replacement for C-style switch statements) are met. 

<P></P>

<P>There it is, if in a nutshell. </P>

<P><FONT size=-2><A 

href="#top">Back 

to top</A></FONT></P>

<HR>



<H3 align=center><A name=for>For Ever...</A></H3>

<P>Wow, don't I come up with the worst section titles? Anyway, on to the next 

standard loop: the for loop. Python's for loop is probably a bit different from 

those you've seen, unless you've seen perl's or PHP's foreach loop. for loops in 

Python run through each item in a string or list and assign it to a particular, 

specified variable. The syntax is intuitive and might even resemble human 

speech. Watch and learn: <PRE>&gt;&gt;&gt; for letter in "Brian": #Blocks are treated the same way as above

...     print letter

...     #This just prints each letter in "Brian" on its own line

...

B

r

i

a

n

</PRE>Very simple. But you might say this odd for loop is lacking because it 

doesn't go through, for example, the numbers from 1 to 10 and put them in i, 

like in *other* languages. That is easily overcome with the ubiquitously useful 

range() function. range() will return a list, perfect for running through with 

for, of numbers in a specified range (now where do those Python creators come up 

with those names?). You can specify one of a number of arguments, as follows: <PRE>&gt;&gt;&gt; #This returns a list of 6 numbers, starting at 0

... range(6) #which means the argument you put there is not actually in the list.

[0, 1, 2, 3, 4, 5]

&gt;&gt;&gt; #A list from 6 to 10-1, or 6-9.

... range(6,10) Remember 10 doesn't actually appear, just like above.

[6, 7, 8, 9]

&gt;&gt;&gt; range(6,10,2) #Same as above, only increments by 2.

[6, 8]

&gt;&gt;&gt; range(10,6,-1) #Negative increments work too. The last number, 6, still doesn't appear.

[10, 9, 8, 7]

</PRE>Those should have been pretty much self-explanatory. Another little trick, 

if you want to iterate through the elements in a list by index number, is to use 

the len() function (which returns the length of the list) together with the 

range() function: <PRE>&gt;&gt;&gt; l = ["I'm", "not", "dead"]

&gt;&gt;&gt; for i in range(len(l)):

...     print "Item", i, "of l is "+l[i]

...

Item 0 of l is I'm

Item 1 of l is not

Item 2 of l is dead

</PRE>Well, that about wraps it up for for loops. Remember: if you can't come to 

grips with for really being a foreach, range() is your friend. 

<P></P>

<P><FONT size=-2><A 

href="#top">Back 

to top</A></FONT></P>

<HR>



<H3 align=center><A name=while>While We...and Others</A></H3>

<P>I'm not even going to <I>say</I> anything about this title. Moving on, then, 

to the last of the ever-so-common loops: while. while performs its little block 

of code forever and ever, or at least until some predefined condition is met. <PRE>&gt;&gt;&gt; while name != "Dave"

...     name = raw_input( "What's my name? " )

...

What's my name? David

What's my name? Monty

What's my name? Dave

&gt;&gt;&gt;

</PRE>Notice how it obstinately refuses to let me go on until I give it what 

it's looking for. Of course, while loops need not be dependent on user input. 

This loop here will calculate every cube that's under 1000: <PRE>&gt;&gt;&gt; c = 0

&gt;&gt;&gt; while c**3 &lt;= 1000:

...     print `c`+"^3="+`c**3`

...     c = c + 1

...

0^3=0

1^3=1

2^3=8

3^3=27

4^3=64

5^3=125

6^3=216

7^3=343

8^3=512

9^3=729

10^3=1000

</PRE>A few other features of loops bear mentioning: break, continue, and else. 

break will completely break out of a loop, bypassing any statements (and else 

clauses, as we shall see). continue will stop where it is in the loop and go on 

with the next iteration. else clauses, which can be used on any loop (not just 

if), specify code to execute after the loop is finished, e.g. in a for loop 

there are no more items to iterate through. Look at this 

slightly-modified-but-still-cheesy example: <PRE>&gt;&gt;&gt; for i in range(3):

...     name = raw_input( "What's my name? " )

...     if name != "Dave":

...             print "Wrong!"

...             continue

...     else:

...             print "Damn straight!"

...             break

... else:

...             print "Too many guesses! You're wrong!"

...

What's my name? David

Wrong!

What's my name? David

Wrong!

What's my name? David

Wrong!

Too many guesses! You're wrong!

&gt;&gt;&gt; #Try it again, but I won't type the code here again

What's my name? Dave

Damn straight!

</PRE>Well, so much for control structures... 

<P></P>

<P><FONT size=-2><A 

href="#top">Back 

to top</A></FONT></P>

<HR>



<H2 align=center><A name=inter>Intermediate Python</A></H2>

<H3 align=center><A name=tuples>Tuples!</A></H3>

<P>Well, here we are, at the much-hyped tuple section. Tuples are another type 

of variable that resemble lists but are more general and have a wider range of 

features. They are usually put in parentheses (), but sometimes parentheses 

aren't even necessary to assign them: <PRE>&gt;&gt;&gt; t = (1, 2, 3) #Wow, our first tuple :)

&gt;&gt;&gt; t

(1, 2, 3)

&gt;&gt;&gt; t + 1, 2, 3 #Who needs parentheses? Well most of the time you do...

&gt;&gt;&gt; t

(1, 2, 3)

&gt;&gt;&gt; t[0] #Still use brackets to get indexes

1

&gt;&gt;&gt; t = 1, #You need the trailing comma, or else t is just an int

(1)

</PRE>Great, you say, but what makes these "tuples" more special than any old 

lists? Well, for one thing, tuples can be nested in one another: <PRE>&gt;&gt;&gt; tu = tuple(range(1,4)) #Note use of tuple function

&gt;&gt;&gt; ple = tuple(range(4,7))

&gt;&gt;&gt; tuples = tu, ple

&gt;&gt;&gt; tuples

((1, 2, 3), (4, 5, 6))

&gt;&gt;&gt; print tuples[1][1] #Access it like this

5

</PRE>Nesting tuples together like this can provide a substitute for things like 

two-dimensional arrays (arrays of arrays) in C without all that pesky pointing. 

Also notice, just for convenience, the tuple() function. This just converts any 

old list into any old tuple. Its opposite, the list() function, also exists. 

There's another little nifty feature of tuples that bears talking about: packing 

and unpacking. Packing a tuple is basically what we've seen above, putting two 

or more variables in a tuple just with commas. Unpacking can also be useful. Try 

to see how this works: <PRE>&gt;&gt;&gt; n = tuple(range(1,6))

&gt;&gt;&gt; a1, a2, a3, a4, a5 = n

&gt;&gt;&gt; print a1, a2, a3, a4, a5

1 2 3 4 5

</PRE>In case you didn't quite understand that, what the second line did was 

take each member of the tuple n and assign it to a different variable, a1 

through a5. This unpacking, just so you know, also works with lists. Just put 

the list of variables in list brackets []. Note how these two examples do the 

same thing: <PRE>&gt;&gt;&gt; l = range(1,4)

&gt;&gt;&gt; [l1, l2, l3] = l

&gt;&gt;&gt; t1, t2, t3 = tuple(l)

&gt;&gt;&gt; print l1, l2, l3, "\n", t1, t2, t3

1 2 3

1 2 3

</PRE>When you're unpacking a bunch of tuples, just remember that the number of 

variables in your list has to equal the length of the tuple. There is one more 

interesting opportunity afforded by tuple packing and unpacking, namely multiple 

assignment. It may seem like this has nothing whatsoever to do with tuples, but 

look now, I'll explain later: <PRE>&gt;&gt;&gt; a, b = 0, 1

&gt;&gt;&gt; a

0

&gt;&gt;&gt; b

1

</PRE>Look at that, a and b assigned different values in the same line! Very 

useful, very simple. Now, since this is the <I>Intermediate</I> section, an 

explanation (rather simple though) is in order. First look on the right: the 

values 0 and 1 are packed into a "temporary" tuple. which I'll call t but I'm 

not sure really has a name. Now on the left. a and b, since they are a 

comma-separated sequence, are about to receive an unpacked tuple. This tuple is 

t. Just like normal unpacking, the first element of t goes in a and the second 

in b. Voila! There's your multiple assignment. 

<P></P>

<P><FONT size=-2><A 

href="#top">Back 

to top</A></FONT></P>

<HR>



<H3 align=center><A name=string>Strings and Slice Indexing</A></H3>

<P>Remember waaayyy back up <A 

href="#slice">somewhere</A> 

where I had a string indexed like a[1:]? Well, that's a simple example of slice 

indexing. With slice indexing you can take more than just one element of a 

string (or list or tuple, but it's usually more useful with strings), in fact 

you can take a whole slice out of it (hence the name). Just put two numbers, the 

starting and ending indices, inside your brackets. Observe: <PRE>&gt;&gt;&gt; s = 'supercalifragalisticexpialidotious'

&gt;&gt;&gt; s[0:5]

'super'

</PRE>Wait, that's not right! Element 5 of s is 'c', not 'r'! Well, I lied 

before. The second number is one more than the highest index you want. (Remember 

range()? It's just like that.) Another one of those things you'll just have to 

deal with, I guess. 

<P></P>

<P>Now, what about that example I gave earlier? There was no second index, 

right? Precisely. There are of course default indexes for before and after the 

:. Before the colon defaults to 0, after defaults to len(s), or the length of 

the string: <PRE>&gt;&gt;&gt; s = 'supercalifragalisticexpialidotious'

&gt;&gt;&gt; s[:5]

'super'

&gt;&gt;&gt; s[27:]

'dotious'

</PRE>You may think it inconvenient to have to count all the way to the 27th 

letter of s in order to get dotious. Say you just wanted the last 7 letters. 

Remember I said negative index numbers work too? Well they do here, too, with 

slicing. Just make sure the beginning index comes before the ending (you'll see 

what I mean): <PRE>&gt;&gt;&gt; s = 'supercalifragalisticexpialidotious'

&gt;&gt;&gt; s[-7:]

'dotious'

&gt;&gt;&gt; s[int(-.5*len(s)):len(s)-5] #Indices can be any int expressions

'ticexpialido'

&gt;&gt;&gt; s[:] #A plain colon is the same as no colon

'supercalifragalisticexpialidotious'

&gt;&gt;&gt; s[:10]+s[10:] #As a rule of thumb, s[:n]+s[n:]=s

'supercalifragalisticexpialidotious'

&gt;&gt;&gt; s[-5:5]

''

</PRE>See what happens when the indices don't match up? No string. Hey, it's 

better than an error, but still not what you want. Moving on, then, why would I 

devote an entire section to slice indexing? Well, I think it's pretty damn neat. 

It also lets you splice (not slice, splice) together strings in weird and 

sometimes cool (not to mention useful) ways. Look at this non-useful way: <PRE>&gt;&gt;&gt; #Mixes two names together. You could make this more sophisticated, like making sure

... #a vowel in the first name is followed by a consonant in the second.

... name1 = raw_input( "Type a name: " )

Type a name: Dave

&gt;&gt;&gt; name2 = raw_input( "Type another name: " )

Type another name: Guido

&gt;&gt;&gt; print name1[:3]+name2[-3:]

Davido

</PRE>Of course, I'm sure you'll find much more practical uses for splicing and 

slicing, but hey, I gotta show you how it works first, don't I? 

<P></P>

<P><FONT size=-2><A 

href="#top">Back 

to top</A></FONT></P>

<HR>



<H3 align=center><A name=fileio>File I/O</A></H3>

<P>How can you have a programming language without a way to access other files 

on the system? I really don't know, but that's alright since Python can do it. 

Well, then you're probably wondering how. Basically, first you need to open the 

file and assign it to an object. Object? We haven't talked about those, have we? 

Objects are like structures (more properly classes) in C, record in some other 

languages. Basically they are a data type that is made up of other data types 

combined, including (and in some cases especially) functions. File handles 

(variables that refer to a file to be opened) are, predictably, of the file 

object type. You assign a file handle using the open function, like this: <PRE>&gt;&gt;&gt; f = open( "myfile.txt", "r" )

&gt;&gt;&gt; f                                #This will vary

&lt;open file 'myfile.txt', mode 'r' at 0x8122338&gt;

</PRE>I hope you know what myfile.txt is (hint: the file to be opened). The "r" 

part is a mode for opening the file. The mode you open the file in tells Python 

whether you're going to read data from the file, write data to the file, etc. 

Here's a list of the modes you can use: 

<UL>

  <LI>r - Reading 

  <LI>w - Writing 

  <LI>a - Appending (same as writing, only any new data is written at the end of 

  the file) 

  <LI>r+ - Reading and writing 

  <LI>No argument - Reading </LI></UL>Note that Python won't give you an error if 

you specify some mode other than these. Be warned that it might make some 

unexpected things happen later on, though. In Windows and MacOS there is also a 

binary mode, "b", which is important but a bit confusing. Binary mode treats all 

characters as normal characters, including newlines. The other modes, as we 

shall soon see, can rely on newlines to separate or find data. The first of 

these newline-using methods is readline. To access the readline method for a 

file object, put 'readline()' after the object's name and a period. This returns 

a string containing the next line in a file. Also available is readlines, which 

reads all the lines of a file into a list. readlines can take an optional 

argument that specifies the most bytes it should read from the file, plus 

whatever it needs to reach the end of a line. One more thing: readline (or 

readlines) returns an empty string '' if the end of the file has been reached. 

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲天天做日日做天天谢日日欢 | 91麻豆精品国产无毒不卡在线观看| 日本成人超碰在线观看| 国产亚洲va综合人人澡精品| 欧美午夜精品电影| 国产成人av电影在线播放| 亚洲mv在线观看| 国产精品美女久久久久aⅴ| 91精品国产入口| 色婷婷亚洲精品| 粉嫩一区二区三区性色av| 日韩精品久久久久久| 亚洲色大成网站www久久九九| 欧美成人精品福利| 欧美性色黄大片手机版| 99久久精品国产麻豆演员表| 久久成人羞羞网站| 日韩av网站在线观看| 亚洲另类在线视频| 国产欧美一区二区三区在线看蜜臀| 欧美精品久久99| 91麻豆123| 91小视频在线| 91麻豆福利精品推荐| 成人性生交大片免费看视频在线| 久久精品国产网站| 日韩av中文在线观看| 午夜国产精品一区| 亚洲成人资源网| 亚洲高清不卡在线| 亚洲夂夂婷婷色拍ww47| 亚洲日本韩国一区| 中文字幕电影一区| 欧美激情综合五月色丁香| 久久综合给合久久狠狠狠97色69| 精品999久久久| 精品国产精品一区二区夜夜嗨| 欧美高清www午色夜在线视频| 欧美老女人第四色| 欧美日韩激情一区| 欧美精品日韩精品| 日韩欧美一级二级三级久久久| 欧美一区二区久久久| 欧美丰满一区二区免费视频| 欧美日本一区二区在线观看| 欧美高清视频不卡网| 欧美一区二区视频在线观看2022| 制服丝袜中文字幕亚洲| 欧美大片一区二区三区| 久久夜色精品国产欧美乱极品| 精品国产乱码久久久久久1区2区 | 国产女人aaa级久久久级| 国产精品久线在线观看| 成人免费在线视频| 亚洲国产精品一区二区www| 视频一区二区三区中文字幕| 日韩国产精品91| 国产一区二区三区| 成人一区二区三区在线观看| av一区二区久久| 欧美午夜电影一区| 日韩欧美二区三区| 国产婷婷色一区二区三区| 日韩精品每日更新| 国产一区91精品张津瑜| 丰满亚洲少妇av| 欧洲亚洲精品在线| 777色狠狠一区二区三区| 久久综合九色综合欧美98| 亚洲欧洲另类国产综合| 亚洲成人免费在线| 国产成人日日夜夜| 91色porny蝌蚪| 欧美一区二区三区不卡| 国产免费成人在线视频| 亚洲高清免费观看| 国产美女娇喘av呻吟久久 | 日韩一区二区三区免费看| 久久久久久9999| 亚洲一级二级在线| 国产凹凸在线观看一区二区| 欧美在线视频你懂得| 久久免费电影网| 午夜精品久久久久| 国产sm精品调教视频网站| 欧美午夜寂寞影院| 欧美国产一区在线| 日韩精品电影一区亚洲| 成人黄色在线视频| 精品嫩草影院久久| 一区二区三区免费| 国产aⅴ综合色| 欧美妇女性影城| 成人欧美一区二区三区| 久久草av在线| 欧美日产国产精品| 亚洲欧美日韩综合aⅴ视频| 精彩视频一区二区| 欧美高清激情brazzers| 亚洲女爱视频在线| 国产精品99久久久久久似苏梦涵| 欧美三级电影在线看| 日韩美女啊v在线免费观看| 久久精品国产精品亚洲综合| 91高清视频免费看| 日本一二三不卡| 狠狠色丁香婷综合久久| 在线不卡一区二区| 亚洲一区二区三区小说| 成人av在线资源网站| 久久精品男人天堂av| 麻豆一区二区三区| 欧美一区二区三区在线观看 | 日韩不卡一区二区三区| 欧美午夜精品久久久久久孕妇| 亚洲欧美怡红院| 成人精品一区二区三区中文字幕| 日韩欧美视频一区| 日韩在线播放一区二区| 欧洲视频一区二区| 一区二区三区在线视频免费观看| 粉嫩av一区二区三区在线播放| 亚洲精品一区二区三区99| 日韩成人免费看| 在线观看91精品国产麻豆| 亚洲国产另类精品专区| 色拍拍在线精品视频8848| 亚洲三级电影全部在线观看高清| 成人激情小说网站| 国产精品狼人久久影院观看方式| 国产麻豆精品theporn| 欧美变态凌虐bdsm| 久久国产三级精品| 精品国产制服丝袜高跟| 久久国产欧美日韩精品| 欧美v日韩v国产v| 久久99精品国产91久久来源 | 亚洲一区精品在线| 在线观看视频一区二区欧美日韩| 一级中文字幕一区二区| 欧美无人高清视频在线观看| 亚洲午夜激情av| 91麻豆精品国产91久久久久| 青草av.久久免费一区| 日韩欧美一二三| 国产成人精品影视| 国产精品初高中害羞小美女文| 色欧美日韩亚洲| 视频一区二区三区入口| 日韩欧美精品三级| 国产精品亚洲午夜一区二区三区 | 91碰在线视频| 樱桃国产成人精品视频| 欧美日韩国产综合久久| 日本人妖一区二区| 久久久久久亚洲综合影院红桃 | 蜜臀av性久久久久蜜臀aⅴ流畅| 精品久久久久久亚洲综合网| 国产91精品精华液一区二区三区| 国产精品免费视频一区| 一本久道中文字幕精品亚洲嫩| 亚洲成在人线免费| 久久久久久久久久久99999| 成人综合婷婷国产精品久久免费| 亚洲情趣在线观看| 在线播放欧美女士性生活| 精油按摩中文字幕久久| 国产精品第四页| 在线成人免费观看| 粉嫩绯色av一区二区在线观看 | 精品区一区二区| www.欧美亚洲| 午夜精品久久久久影视| 精品久久久久一区二区国产| 成人av在线电影| 亚洲sss视频在线视频| 久久久一区二区| 在线看日本不卡| 国产一区二区精品久久99| 一区二区三区在线看| 日韩欧美国产一区二区三区| 91视频免费观看| 久久国产精品第一页| 亚洲视频 欧洲视频| 日韩美女视频在线| av不卡在线观看| 美女视频网站久久| 亚洲综合网站在线观看| 久久精品一区二区三区不卡牛牛| 色狠狠色噜噜噜综合网| 国产一区二区三区四区五区美女| 亚洲精品乱码久久久久久| 久久免费的精品国产v∧| 欧美视频一区二区| 成人一区二区三区视频在线观看 | 91精品国产综合久久精品| 东方aⅴ免费观看久久av| 日韩不卡一区二区| 亚洲精品国产一区二区三区四区在线 | 久久久精品国产99久久精品芒果|