python
最近更新日期20200807
demoStr = ' Hello! Friends... '
print('[===== 去除空格,特定符號與字元 =====]')
# 輸出結果
print ('去除前後空格:'+demoStr.strip()+'_') #去除前後空格:Hello! Friends..._
print ('去除左側空格:'+demoStr.lstrip()+'_') #去除左側空格:Hello! Friends... _
print ('去除右側空格:'+demoStr.rstrip()+'_') #去除右側空格: Hello! Friends..._
print ('去除右側.的特殊符號:'+demoStr.rstrip().rstrip('.')) #去除右側.的特殊符號: Hello! Friends
# 先去除空格,才可以去除. (可以換成任何符號字元)
print('\n[===== 字串連接 =====]')
# s2 = demoStr.join(['a','_','c'])
demoStr2 ='Hello'
s2 = demoStr2.join(['前端_',';_中間_;',';_後端']) #前端_Hello;_中間_;Hello;_後端
print(s2)
demoStr2+=' 你好!'
print('字串連接:'+demoStr2) #字串連接:Hello 你好!
print('\n[=====尋找字串 =====]')
demoStr3= "a1b2c3d4fc"
print('尋找字串:',demoStr3.find('c')) #尋找字串:4 (第一個找到位置)
print('\n[===== 字串比較 =====]')
s1 = 'abcd'
s2 = 'a123'
print(s1>s2) #True
print(s1==s2) #False
print(s1<s2) #False
s1,s2 ='abcd','a1234'
print(len(s1),len(s2)) # 4 5
s1,s2='abcd','ABC123def'
print('轉成大寫:',s1.upper()) #轉成大寫: ABCD
print('轉成小寫:',s2.lower()) #轉成小寫: abc123def
print('大小寫互換:',s2.swapcase()) #大小寫互換: abc123DEF
print('字母大寫:',s1.capitalize()) #字母大寫: Abcd
s1='www.google.com'
print('分割字串:',s1.split('.')) #分割字串: ['www', 'google', 'com']
S20200808 By YTC
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing