2016年9月18日 星期日

程式集訓 G008:小寫轉大寫

 #coding=utf8

#程式集訓 G008:小寫轉大寫
'''
G008:小寫轉大寫
題目:   (G008) 小寫轉大寫 : 輸入一英文連字串,將所有英文字母轉成大寫印出。
str.upper() 將 str 的英文字母都改成大寫
'''
a=str(input("請輸入一英文連字串:"))
b=str.upper(a)
print("其大寫字串為:",b)


================== RESTART: D:/程式語言 Python 入門/程式集訓/G008.py ==================
請輸入一英文連字串:If you're on a Unix terminal, you can print "\a" to get a terminal bell:
其大寫字串為: IF YOU'RE ON A UNIX TERMINAL, YOU CAN PRINT "\A" TO GET A TERMINAL BELL:
>>> 


源自於
http://pydoing.blogspot.tw/2011/03/python-stringtype.html

字串 (string) 屬於不可變 (immutable) 的序列 (sequence) 型態,可進行以下序列通用的計算

計算描述
x in s判斷 x 是否在 s 中
x not in s判斷 x 是否不在 s 中
s + t連接 s 及 t
s * n, n * s將 s 重複 n 次連接 s 本身
s[i]取得索引值 i 的元素
s[i:j]取得索引值 i 到 j 的子序列
s[i:j:k]取得索引值 i 到 j ,間隔 k 的子序列
len(s)回傳 s 的元素個數
min(s)回傳 s 中的最小值
max(s)回傳 s 中的最大值
s.index(i)取得 s 中第一次出現 i 的索引值
s.count(i)累計 s 中 i 出現的個數


字串型態有以下的方法 (method)

方法描述
str.capitalize()回傳將 str 改成首字母大寫,其餘字母小寫的字串
str.center(width[, fillchar])回傳一個將 str 設置字串中央,長度 width 的新字串, fillchar 為填充字元,預設為空格
str.count(sub[, start[, end]])計算 sub 出現的次數, start 為起始計算索引值, end 為結束索引值
str.encode(encoding="utf-8", errors="strict")回傳 encoding 版本的 bytes 物件
str.endswith(suffix[, start[, end]])判斷 str 是否以 suffix 結尾
str.expandtabs([tabsize])將 tab 符號以 tabsize 的空格數替換
str.find(sub[, start[, end]])回傳 sub 第一次出現的索引值
str.format(*args, **kwargs)進行格式化字串運算
str.index(sub[, start[, end]])回傳 sub 第一次出現的索引值
str.isalnum()判斷字串中的字元是否都是字母或數字
str.isalpha()判斷字串中的字元是否都是字母
str.isdecimal()判斷字串中所有字元是否是十進位數字
str.isdigit()判斷字串中所有字元是否是數字
str.isidentifier()判斷字串是否可作為合法的識別字
str.islower()判斷字串中所有字母字元是否都是小寫字母
str.isnumeric()判斷字串中所有字元是否是數字
str.isprintable()判斷字串中所有字元是否都屬於可見字元
str.isspace()判斷字串是否為空格字元
str.istitle()判斷字串是否適合當作標題
str.isupper()判斷字串中所有字母字元是否都是大寫字母
str.join(iterable)回傳將 str 連結 iterable 各元素的字串
str.ljust(width[, fillchar])回傳將 str 在寬度 width 向左對齊的字串, fillchar 為填充字元,預設為空格
str.lower()將 str 的英文字母都改成小寫
str.lstrip([chars])回傳將 str 左邊具有 chars 字元去除的拷貝版本, chars 預設為空格符號
static str.maketrans(x[, y[, z]])回傳 x 與 y 配對的 Unicode 編碼字典,若有提供 z , z 中的字元會跟 None 配對
str.partition(sep)以 sep 分割 str 為三個部份,結果回傳具有三個子字串的序對
str.replace(old, new[, count])將 str 中的 old 子字串以 new 代換
str.rfind(sub[, start[, end]])尋找最右邊的 sub ,也就是索引值最大的 sub
str.rindex(sub[, start[, end]])尋找最右邊的 sub ,也就是索引值最大的 sub
str.rjust(width[, fillchar])回傳將 str 在寬度 width 向右對齊的字串, fillchar 為填充字元,預設為空格
str.rpartition(sep)以 sep 從最右端分割 str 為三個部份,結果回傳具有三個子字串的序對
str.rsplit([sep[, maxsplit]])將 str 從最右端以 sep 分割成子字串,回傳儲存子字串的串列, maxsplit 為子字串最多的數量
str.rstrip([chars])從 str 的最右端中移除 chars 字元,預設為空白字元
str.split([sep[, maxsplit]])將 str 以 sep 分割成子字串,回傳儲存子字串的串列, maxsplit 為子字串最多的數量
str.splitlines([keepends])將 str 以新行符號分割成子字串,回傳儲存子字串的串列
str.startswith(prefix[, start[, end]])判斷 str 是否以 prefix 開頭
str.strip([chars])從 str 中移除 chars 字元,預設為空白字元
str.swapcase()將 str 中的英文字母進行大小寫轉換
str.title()將 str 轉換成作為標題的字串
str.translate(map)將 str 中的字元以 map 中配對的字元轉換
str.upper()將 str 的英文字母都改成大寫
str.zfill(width)回傳以 0 塞滿 width 的新字串

沒有留言:

張貼留言

Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --3

  Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --3 AngularJS 實例 <!DOCTYPE html> <html> <head> <meta charse...