發表文章

目前顯示的是 3月, 2021的文章

【台股資訊】「三大法人買賣金額統計表」與「法人成交比重」 2021-03-31

圖片
TWSE 臺灣證券交易所 - 報表 110年03月31日 三大法人買賣金額統計表 單位名稱 買進金額 賣出金額 買賣差額 自營商(自行買賣) 4,127,382,735 3,707,428,047 419,954,688 自營商(避險) 6,673,158,863 8,837,374,985 -2,164,216,122

【PYTHON】Python的布林值。 Python Booleans

圖片
  布林值為True或False。 布林值 在程式中你通常需要在if描述式中知道True或False。 你可以評估任何Python的描述式,且得到1或2個答案,True或False。 當你比較2個值時,如下的比較,使用print()列印出布林值: 範例: print ( 10  >  9 ) print ( 10  ==  9 ) print ( 10  <  9 ) 上面輸出: True >>> print(10 == 9) False >>> print(10 < 9) False 當你執行完if描述式時,Python會回傳True或False: 範例: 列印一個訊息基於狀態是True或False: a =  200 b =  33 if  b > a:    print ( "b is greater than a" ) else :    print ( "b is not greater than a" ) 上面輸出: "b is not greater than a" 評估值與變數 使用  bool()  函數 准許你評估任何值, 且會回傳你  True  or  False  , 範例: 使用bool()去評估一個字串與數字: print ( bool ( "Hello" )) print ( bool ( 15 )) 上面輸出: >>> print(bool("Hello")) True >>> print(bool(15)) True >>> 範例 評估二個變數: x =  "Hello" y =  15 print ( bool (x)) print ( bool (y)) >>> print(bool(x)) True >>> print(bool(y)) True >>> 大部分的值為 True 幾乎任何值是用bool()後都會回傳  True  如果內容是排序過的. 任何字串為  True , 除了空字串(empty String). 任何數字為  True

【PYTHON】Python的String。Python String Methods.- Python的字串方法

圖片
  String Methods Python有一系列的預設方法可以操作字串。 Note:   所有字串方法回傳一個新的值。 並不會改變原始字串。 Method Description capitalize() Converts the first character to upper case 轉換第一個字元為大寫 casefold() Converts string into lower case 轉換字串為小寫 center() Returns a centered string 回傳讓字串置中,前面補空白,參數為數字,為前面空白數,讓字串置中。 count() Returns the number of times a specified value occurs in a string encode() Returns an encoded version of the string endswith() Returns true if the string ends with the specified value expandtabs() Sets the tab size of the string find() Searches the string for a specified value and returns the position of where it was found format() Formats specified values in a string format_map() Formats specified values in a string index() Searches the string for a specified value and returns the position of where it was found isalnum() Returns True if all characters in the string are alphanumeric isalpha() Returns True if all characters in the string are in the alphabet isdecimal() Returns True if all characters in th

【台股資訊】「三大法人買賣金額統計表」與「法人成交比重」 2021-03-30

圖片
TWSE 臺灣證券交易所 - 報表 110年03月30日 三大法人買賣金額統計表 單位名稱 買進金額 賣出金額 買賣差額 自營商(自行買賣) 5,063,699,782 3,710,414,878 1,353,284,904 自營商(避險) 9,051,963,066 6,025,512,467 3,026,450,599

【台股資訊】「三大法人買賣金額統計表」與「法人成交比重」 2021-03-29

圖片
  110年03月29日 三大法人買賣金額統計表 單位名稱 買進金額 賣出金額 買賣差額 自營商(自行買賣) 3,676,328,056 3,467,481,648 208,846,408 自營商(避險) 8,640,223,108 7,083,645,220 1,556,577,888

【PYTHON】Python的String。Python escape Characters.- Python的跳脫字元

圖片
跳脫字元 使用跳脫字元的情境在,當需要在字串內插入一個非法的字元來顯示。 使用反斜線  \  為跳脫字元之後跟隨著需要插入的字元。 在字串裡面在夾雜2個雙引號間如果再使用雙引號是個錯誤的範例,如下所示: 範例: 你將會出現錯誤訊息,如果你使用雙引號在其中間又加入雙引號: txt =  "We are the so-called " Vikings " from the north." 上面輸出錯誤訊息:  File "<stdin>", line 1     txt = "We are the so-called "Vikings" from the north."                                        ^ SyntaxError: invalid syntax  為解決這個問題, 我們試用跳脫字元  \" : 範例: 當使用跳脫字元就可用雙引號,正常在引號內不可以在有裡面的雙引號,如同不可巢狀雙引號。 txt =  "We are the so-called \" Vikings\ " from the north. print(txt) 上面輸出: We are the so-called "Vikings" from the north. 跳脫字元表 其他在Python中使用的跳脫字元表: Code Result Try it \' Single Quote Try it » \\ Backslash Try it » \n New Line Try it » \r Carriage Return Try it » \t Tab Try it » \b Backspace Try it » \f Form Feed \ooo Octal value Try it » \xhh Hex value Try it »

【PYTHON】Python的String。Python String Format.-字串格式

圖片
  字串格式 在我們學習Python變數時,當我們將字串與數字使用+號連結時,會出現錯誤訊息,無法將2種不同資料格式的變數使用+號直接合併。 範例: money = 5 txt =  "My name is John, and I have "  + money +  "dollars." print (txt) 錯誤訊息:TypeError: can only concatenate str (not "int") to str 但我們可以結合字串與數字使用format() method來完成。 format()方法對參數傳遞,會先格式化他們,且使用 {} 來傳遞變數。 範例: Use the  format()  method to insert numbers into strings: money = 5 txt =  "My name is John, and I have {} dollars in my pocket." print (txt. format (money)) 上面輸出:My name is John, and I have 5 dollars in my pocket. 可以看出上面format()會傳遞{}裡面的變數。 The format() 方法不限參數的數量,且會依照循序的填入參數。 範例: quantity =  3 itemno =  567 price =  49.95 myorder =  "I want {} pieces of item {} for {} dollars." print (myorder. format (quantity,  itemno, price)) 上面輸出:I want 3 pieces of item 567 for 49.95 dollars. 也可使用index來指定哪一個參數顯示,如下範例: 範例: quantity =  3 itemno =  567 price =  49.95 myorder =  "I want to pay {2} dollars for {0} pieces of item {1}." print (myorder. format

【PYTHON】Python的String。Python String Concatenation.-字串合併

圖片
  Python的字串合併 在Python中要合併2個字串,可以使用+號。 範例: 將變數  a  與變數  b  合併為變數  c : a =  "Hello" b =  "World" c = a + b print (c) 上面輸出:HelloWorld 範例: 在2個變數中增加一個空白符號 " " : a =  "Hello" b =  "World" c = a +  " "  + b print (c) 上面輸出:Hello World that's it.