亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 編程 > Python > 正文

The Python Tutorial 筆記

2019-11-06 07:57:38
字體:
來源:轉載
供稿:網友

Source

2. Using the Python InterPReter

2.1. Invoking the Interpreter

添加path
set path=%path%;C:/python36widows 退出解釋器: ^Z or quit()

The interpreter’s line-editing features include interactive editing, history substitution and code completion on systems that support readline.Perhaps the quickest check to see whether command line editing is supported is typing Control-P to the first Python prompt you get. If it beeps, you have command line editing; see Appendix Interactive Input Editing and History Substitution for an introduction to the keys. If nothing appears to happen, or if ^P is echoed, command line editing isn’t available; you’ll only be able to use backspace to remove characters from the current line.

Control-P會觸發提示窗"Print to defaut printer", 似乎和其他應用有熱鍵沖突。 行編輯功能不能使用。

The interpreter Operates somewhat like the Unix shell: when called with standard input connected to a tty device, it reads and executes commands interactively; when called with a file name argument or with a file as standard input, it reads and executes a script from that file.

A second way of starting the interpreter is python -c command [arg] ..., which executes the statement(s) in command, analogous to the shell’s -c option. Since Python statements often contain spaces or other characters that are special to the shell, it is usually advised to quote command in its entirety with single quotes.

Some Python modules are also useful as scripts. These can be invoked using python -m module [arg] ..., which executes the source file for module as if you had spelled out its full name on the command line.

When a script file is used, it is sometimes useful to be able to run the script and enter interactive mode afterwards. This can be done by passing -i before the script.

All command line options are described in Command line and environment.

2.1.1. Argument Passing

When known to the interpreter, the script name and additional arguments thereafter are turned into a list of strings and assigned to the argv variable in the sys module. You can access this list by executing import sys. The length of the list is at least one; when no script and no arguments are given, sys.argv[0] is an empty string. When the script name is given as '-' (meaning standard input), sys.argv[0] is set to '-'. When -c command is used, sys.argv[0] is set to '-c'. When -m module is used, sys.argv[0] is set to the full name of the located module. Options found after -c command or -m module are not consumed by the Python interpreter’s option processing but left in sys.argv for the command or module to handle.

2.1.2. Interactive Mode (是什么?)

the primary prompt usually three greater-than signs (>>>); 比如在windows cmd下輸入python,則顯示:

C:/Users/xxxxx>pythonPython 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32Type "help", "copyright", "credits" or "license" for more information.>>>continuation linesit prompts with the secondary prompt, by default three dots (...). Continuation lines are needed when entering a multi-line construct. 一次輸入多行代碼,代碼體內部行用secondary prompt打頭。

2.2. The Interpreter and Its Environment

2.2.1. Source Code Encoding

By default, Python source files are treated as encoded in UTF-8. 編輯器需要識別UTF-8編碼,所用字體也用支持UTF-8

不使用默認編碼要明示,通常在源程序文件首行。

# -*- coding: encoding -*-

3. An Informal Introduction to Python

Note that a secondary prompt on a line by itself in an example means you must type a blank line; this is used to end a multi-line command. 多行命令用空行終止

python的注釋號  #, 字符串中的#不算注釋開頭

3.1. Using Python as a Calculator

>>> 8 / 5  # division always returns a floating point number1.6區別于C/C++ 整型相除得到整型

int 整型 float 浮點型

floor division 用 //取余 %

乘方 **

賦值=

The equal sign (=) is used to assign a value to a variable. Afterwards, no result is displayed before the next interactive prompt:

未賦值的變量不能直接使用

In interactive mode, the last printed expression is assigned to the variable _

上一個表達式計算結果存在變量_中,  _當作只讀用,不要對其賦值,否則就相當于定義了新的同名變量,不再有存前結果的功能

取小數位 round( 3.14159, 2)   3.14

其他數據類型Decimal, Fraction, complex number

3.1.2. Strings

字符串“” 和''等效,交互模式下,解釋器會用單引號,用反斜杠escape特殊符號

print()會直接把根據escape符號意義打印,如果不希望這么做, 使用raw string, 

>>> print('C:/some/name')  # here /n means newline!C:/someame>>> print(r'C:/some/name')  # note the r before the quoteC:/some/name

字符串可以占多行 """ """ ''' ''' 

+連接字符串    * 重復

字符串常量挨著會自動合并, 用于代碼中字符串拆多行,用括號括起來就可以

>>> text = ('Put several strings within parentheses '...         'to have them joined together.')>>> text'Put several strings within parentheses to have them joined together.'字符串索引,可正可負,從左數從0開始加,從右數從-1開始減

如何取子串, str[a,b] str[:a] str[b:]  含左不含右

字符串不能改變,給字符串字符賦值會引起報錯

拓展

Text Sequence Type — strStrings are examples of sequence types, and support the common operations supported by such types.String MethodsStrings support a large number of methods for basic transformations and searching.Formatted string literalsString literals that have embedded expressions.Format String SyntaxInformation about string formatting with str.format().printf-style String FormattingThe old formatting operations invoked when strings are the left operand of the % operator are described in more detail here.

3.1.3. Lists

和字符串一樣可以去子列表。子列表操作會返回一個新的對象。

列表可以合并

>>> squares + [36, 49, 64, 81, 100][1, 4, 9, 16, 25, 36, 49, 64, 81, 100]列表可以修改

append()在列表尾部添加

直接修改子列表

用空列表修改,相當于刪除

列表可以嵌套

>>> a = ['a', 'b', 'c']>>> n = [1, 2, 3]>>> x = [a, n]>>> x[['a', 'b', 'c'], [1, 2, 3]]>>> x[0]['a', 'b', 'c']>>> x[0][1]'b'

3.2. First Steps Towards Programming

01 >>> # Fibonacci series:(動態規劃版)02 ... # the sum of two elements defines the next03 ... a, b = 0, 104 >>> while b < 10:05 ...     print(b)06 ...     a, b = b, a+b07 ...

03,  a multiple assignment, the variables a and b simultaneously get the new values 0 and 1.

06, again, the expressions on the right-hand side are all evaluated first before any of the assignments take place. The right-hand side expressions are evaluated from the left to the right.  右邊兩部分表達式先估值再同時分別付給左邊兩個變量,=右側兩個表達式從左到右估值

In Python, like in C, any non-zero integer value is true; zero is false.  非零true 零false 非空串true 空串false

比較運算符同C

python靠縮進來組織代碼塊,同一塊中的語句縮進量需要相等,用空行來結束代碼塊。

 print() 可以嚴格控制輸出格式。用end=' x',可以避免換行。

>>> a, b = 0, 1>>> while b < 1000:...     print(b, end=',')...     a, b = b, a+b...1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
欧美日韩一区二区三区| 日韩精品在线视频美女| 欧美精品免费在线观看| 日韩中文字幕在线视频播放| 日韩av最新在线| 欧美日韩成人在线观看| 亚洲国产精品va在线看黑人动漫| 成人激情视频免费在线| 亚洲最大中文字幕| 性色av一区二区三区在线观看| 久久香蕉频线观| 91av成人在线| 97视频在线观看亚洲| 久久久久久久久久久久久久久久久久av| 欧美放荡办公室videos4k| 国产不卡一区二区在线播放| 97超级碰在线看视频免费在线看| 97婷婷大伊香蕉精品视频| 欧美最近摘花xxxx摘花| 狠狠久久五月精品中文字幕| 国产精品免费久久久久影院| 欧美人交a欧美精品| 78m国产成人精品视频| 欧美精品aaa| 欧美成年人在线观看| 一区二区三区视频免费在线观看| 国产有码在线一区二区视频| 亚洲欧洲在线看| 日韩高清电影免费观看完整版| 精品亚洲永久免费精品| 成人xxxx视频| 国产成人av网址| 亚洲国产精品久久久久秋霞蜜臀| 精品国产999| 色噜噜国产精品视频一区二区| 欧美日韩另类视频| 亚洲色图校园春色| 久久电影一区二区| 日韩欧美中文字幕在线播放| 国产精品99久久久久久人| 久久精品国产亚洲| 亚洲精品在线91| 久久97精品久久久久久久不卡| 亚洲乱亚洲乱妇无码| 国产精品女人网站| 亚洲а∨天堂久久精品9966| 5566成人精品视频免费| 亚洲国产一区二区三区四区| 91精品国产精品| 久久亚洲国产精品成人av秋霞| 这里只有精品视频| 欧美黄色片免费观看| 亚洲自拍高清视频网站| 国产欧美日韩最新| 国产国产精品人在线视| 国产日产欧美精品| 国产精品久久久久免费a∨大胸| 日韩欧美中文第一页| 亚洲国产一区自拍| 欧美性xxxx| 日韩在线高清视频| 精品亚洲va在线va天堂资源站| 懂色aⅴ精品一区二区三区蜜月| 欧美高清第一页| 青青a在线精品免费观看| 国产69精品久久久久9999| 国内精品一区二区三区| 97超级碰碰人国产在线观看| 91久久精品国产91久久| 国产精品日韩欧美综合| 亚洲精品aⅴ中文字幕乱码| 成人av色在线观看| 成人免费看黄网站| 亚洲国产成人爱av在线播放| 久久人人爽人人爽人人片av高请| 国产精品三级网站| 国产精品久久二区| 日韩欧美在线中文字幕| 日韩亚洲精品电影| 91精品免费看| 夜夜狂射影院欧美极品| 亚洲欧美日韩一区二区在线| 日韩欧美国产免费播放| 中文字幕在线看视频国产欧美在线看完整| 国产在线视频一区| 亚洲一区二区久久久久久久| 国产欧美精品一区二区| 久热爱精品视频线路一| 亚洲老头同性xxxxx| 亚洲日韩中文字幕| 欧美另类精品xxxx孕妇| 久久久免费电影| 亚洲国产另类 国产精品国产免费| 久久免费视频在线观看| 国产亚洲精品综合一区91| 欧美精品videosex极品1| 国产精品第三页| 久久久精品999| 日韩中文在线观看| 亚洲人成电影在线观看天堂色| 欧美极品少妇xxxxⅹ裸体艺术| 国产伦精品一区二区三区精品视频| 欧美猛交ⅹxxx乱大交视频| 欧美性猛交xxxx富婆| 欧美成人激情图片网| 欧日韩不卡在线视频| 久久久久久av| 精品国产91久久久| 欧洲亚洲免费在线| 国产亚洲成精品久久| 日韩av一区在线观看| 欧美精品在线第一页| 国产精品高潮呻吟久久av黑人| 亚洲精品999| 国产精品一区二区av影院萌芽| 88xx成人精品| 狠狠躁天天躁日日躁欧美| 欧美精品videosex牲欧美| 亚洲欧洲一区二区三区在线观看| 黑人狂躁日本妞一区二区三区| 国产精品久久久久久久久久免费| 久久99国产精品久久久久久久久| 国产丝袜视频一区| 国产视频亚洲精品| 成人国内精品久久久久一区| 亚洲精品久久久久中文字幕欢迎你| 欧美刺激性大交免费视频| 欧美日韩亚洲视频| 亚洲精品一区二区三区婷婷月| 精品国产乱码久久久久酒店| 国产噜噜噜噜噜久久久久久久久| 91精品在线播放| 久久在线观看视频| 久久影视电视剧免费网站| 国产一区二区三区毛片| 国产精品aaa| 日韩欧美aⅴ综合网站发布| 黑人极品videos精品欧美裸| 日韩av一区二区在线观看| 在线视频欧美日韩精品| 米奇精品一区二区三区在线观看| 成人写真视频福利网| 国产ts人妖一区二区三区| 久久影视电视剧免费网站清宫辞电视| 中日韩美女免费视频网站在线观看| 国产视频精品在线| 国产精品久久久久久亚洲影视| 色噜噜狠狠狠综合曰曰曰| 日韩免费av一区二区| www高清在线视频日韩欧美| 57pao精品| 欧美性猛交xxxxx水多| 欧美激情极品视频| 国产精品国产自产拍高清av水多| 草民午夜欧美限制a级福利片| 91av视频在线播放| 精品高清美女精品国产区| 国产精品入口尤物| 精品亚洲aⅴ在线观看| 曰本色欧美视频在线| 成人性生交大片免费看小说| 亚洲欧美制服丝袜| 亚洲第一免费网站| 亚洲开心激情网|