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

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

?? python for newbies.htm

?? 1000 HOWTOs for various needs [WINDOWS]
?? 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一区二区三区免费野_久草精品视频
国产视频在线观看一区二区三区| 日韩欧美一级特黄在线播放| 国产精品1024久久| 久久国产精品区| 久久99国产精品免费| 久久狠狠亚洲综合| 国产精品自拍av| 国产福利一区在线| 国产成人精品影院| 91蝌蚪porny| 欧美视频在线播放| 日韩美女视频在线| 精品国产免费视频| 国产精品欧美久久久久无广告| 欧美国产日本韩| 亚洲欧美经典视频| 日韩国产欧美三级| 国产激情一区二区三区| 成人不卡免费av| 欧美视频中文一区二区三区在线观看| 欧美日韩在线三级| 日韩欧美国产午夜精品| 欧美国产精品一区二区| 夜色激情一区二区| 久久99精品视频| 99视频精品全部免费在线| 欧美久久免费观看| 国产精品女上位| 午夜精品久久久久久久久| 精品一区二区三区免费毛片爱 | 极品少妇一区二区| 成人综合婷婷国产精品久久蜜臀| 色欧美片视频在线观看| 欧美电影免费观看高清完整版在 | 国产亚洲一区二区在线观看| 亚洲欧美自拍偷拍色图| 久久精品国产网站| 日本高清无吗v一区| 久久九九全国免费| 亚洲成人一区二区在线观看| 高清久久久久久| 91麻豆精品久久久久蜜臀 | 欧美性一级生活| 久久人人97超碰com| 亚洲国产精品欧美一二99| 国产精品白丝jk黑袜喷水| 337p亚洲精品色噜噜噜| 自拍偷自拍亚洲精品播放| 久久精品国产久精国产爱| 欧美人妖巨大在线| 亚洲免费观看高清完整版在线| 国产精品一二一区| 欧美一区二区视频观看视频 | 69av一区二区三区| 亚洲男人天堂av网| 成人性生交大片免费看视频在线 | 国产精品成人午夜| 国产精品中文欧美| 26uuu精品一区二区在线观看| 午夜视频在线观看一区二区| 91在线码无精品| 国产精品丝袜一区| 国产大陆亚洲精品国产| 精品电影一区二区| 激情综合色丁香一区二区| 欧美放荡的少妇| 亚洲v中文字幕| 欧美色国产精品| 一区二区三区精品| 日本乱码高清不卡字幕| 亚洲精品乱码久久久久久黑人| 99久久99久久免费精品蜜臀| 国产精品久久毛片| 成人激情动漫在线观看| 久久久久久电影| fc2成人免费人成在线观看播放| 欧美激情中文不卡| 成人国产精品免费观看| 国产精品色哟哟网站| 成人国产免费视频| 中文字幕制服丝袜成人av| 成人毛片在线观看| 亚洲图片欧美激情| 欧美视频一区二| 免费观看一级欧美片| 久久久精品国产免费观看同学| 国产麻豆成人精品| 亚洲色图19p| 91视频国产观看| 亚洲综合免费观看高清完整版在线| 欧美日韩综合在线| 美女一区二区久久| 欧美高清在线视频| 日本精品一区二区三区高清| 日日夜夜免费精品视频| 久久欧美中文字幕| 91麻豆文化传媒在线观看| 五月综合激情婷婷六月色窝| 日韩欧美的一区| 成人久久久精品乱码一区二区三区| 中文字幕在线一区二区三区| 欧美老女人第四色| 国产美女精品一区二区三区| 日韩理论片中文av| 精品精品欲导航| 一本到一区二区三区| 日韩**一区毛片| 1024成人网色www| 日韩欧美成人一区| 91免费国产视频网站| 日本欧美韩国一区三区| 亚洲欧美在线高清| 欧美大片日本大片免费观看| 97se亚洲国产综合在线| 免费成人在线播放| 一区二区在线看| 国产亚洲欧美色| 91精品国产美女浴室洗澡无遮挡| 国产精品一区二区三区四区| 午夜久久福利影院| 亚洲天堂精品在线观看| 久久这里只精品最新地址| 欧美三级电影在线看| 成人免费高清在线观看| 久国产精品韩国三级视频| 亚洲6080在线| 亚洲免费伊人电影| 国产精品久久久久毛片软件| 精品国产免费人成在线观看| 欧美日韩国产在线观看| 91小视频免费观看| 高清国产一区二区| 精品午夜一区二区三区在线观看| 亚洲国产日韩a在线播放| 国产精品久久久久久久久久免费看| 精品日韩在线一区| 欧美一级日韩免费不卡| 欧美性高清videossexo| 色噜噜夜夜夜综合网| 91蝌蚪porny| 91在线观看视频| va亚洲va日韩不卡在线观看| 成人中文字幕合集| 国产99久久久久| 国产盗摄视频一区二区三区| 久久av资源站| 国产一区美女在线| 韩国在线一区二区| 国产伦精一区二区三区| 国产激情视频一区二区三区欧美| 久久99精品久久久久久动态图| 日韩激情视频网站| 蜜臀av一区二区三区| 毛片av一区二区| 狠狠色丁香久久婷婷综合_中| 久久精品国产色蜜蜜麻豆| 国内外成人在线| 国产成人av一区二区| av在线不卡免费看| 一本色道久久综合亚洲91| 91福利小视频| 欧美色图一区二区三区| 欧美电影在哪看比较好| 精品粉嫩超白一线天av| 久久久蜜臀国产一区二区| 日本一区二区视频在线| 国产精品欧美经典| 亚洲午夜一二三区视频| 老汉av免费一区二区三区| 国产福利一区二区三区视频在线| 成人av午夜影院| 欧美午夜在线观看| 精品剧情在线观看| 亚洲欧洲av另类| 日韩电影免费一区| 粉嫩在线一区二区三区视频| 91视视频在线观看入口直接观看www | 欧美sm美女调教| 国产欧美日韩在线| 亚洲精品久久嫩草网站秘色| 日韩专区一卡二卡| 高清成人免费视频| 欧美亚洲尤物久久| 精品国产成人系列| 亚洲欧美一区二区不卡| 欧美aaa在线| 色综合天天综合| 国产亚洲女人久久久久毛片| 国产女人18水真多18精品一级做| 一区二区三区四区五区视频在线观看 | 麻豆一区二区三| 成人av综合一区| 日韩女优av电影| 一区二区三区欧美亚洲| 国产一区二三区好的| 在线看一区二区| 久久久精品日韩欧美| 亚洲成人一区在线| 91亚洲精华国产精华精华液| www久久精品|