天天看點

Python3 與 NetCore 基礎文法對比(String專欄)

彙總系列:https://www.cnblogs.com/dunitian/p/4822808.html#ai

Jupyter排版:https://www.cnblogs.com/dunitian/p/9119986.html

線上浏覽:http://nbviewer.jupyter.org/github/lotapp/BaseCode/tree/master/python/notebook/1.POP/2.str

事先聲明一下,避免讓新手進入誤區:不是說Python比NetCore要好,而Python設計的目的就是==》讓程式員解放出來,不要過于關注代碼本身,那麼性能、規範等等各方面隐患就存在了,後面編寫一個稍微大點的項目就看出來了。而且不要太受語言限制,之前我也說過,用各自語言的優勢來為項目服務~ 這才是開發王道。比如Python用來資料分析,Go用來并發處理等等,不多說了,記住一句話即可:“Net是成本效益最高的”
Python3 與 NetCore 基礎文法對比(String專欄)

步入正題:歡迎提出更簡單或者效率更高的方法

基礎系列:(這邊重點說說Python,上次講過的東西我就一筆帶過了)

1.輸出+類型轉換 Python寫法:
Python3 與 NetCore 基礎文法對比(String專欄)
NetCore:
Python3 與 NetCore 基礎文法對比(String專欄)
2.字元串拼接+拼接輸出方式 python:
Python3 與 NetCore 基礎文法對比(String專欄)
NetCore
Python3 與 NetCore 基礎文法對比(String專欄)
3.字元串周遊、下标、切片 重點說下python的下标,有點意思,最後一個元素,我們一般都是len(str)-1,他可以直接用-1,倒2自然就是-2了 #最後一個元素:user_str[-1] user_str[-1] user_str[len(user_str)-1] #其他程式設計語言寫法 #倒數第二個元素:user_str[-2]
Python3 與 NetCore 基礎文法對比(String專欄)
這次為了更加形象對比,一句一句翻譯成NetCore(有沒有發現規律,user_str[user_str.Length-1]==》-1是最後一個,user_str[user_str.Length-2]==》-2是最後一個。python在這方面簡化了)
Python3 與 NetCore 基礎文法對比(String專欄)
3.2 python切片文法:[start_index:end_index:step] (end_index取不到)
Python3 與 NetCore 基礎文法對比(String專欄)

方法系列:

# 查找:find,rfind,index,rindex Python查找推薦你用find和rfind
Python3 與 NetCore 基礎文法對比(String專欄)
netcore:index0f就相當于python裡面的find
Python3 與 NetCore 基礎文法對比(String專欄)
# 計數:count python:str.count()
Python3 與 NetCore 基礎文法對比(String專欄)
netcore:這個真用基礎來解決的話,兩種方法: 第一種自己變形一下:(原字元串長度 - 替換後的長度) / 字元串長度
Python3 與 NetCore 基礎文法對比(String專欄)
字元串統計另一種方法(就用index)【點我】
Python3 與 NetCore 基礎文法對比(String專欄)

附錄:

Python3:
Python3 與 NetCore 基礎文法對比(String專欄)
Python3 與 NetCore 基礎文法對比(String專欄)
Python3 與 NetCore 基礎文法對比(String專欄)
Python3 與 NetCore 基礎文法對比(String專欄)
Python3 與 NetCore 基礎文法對比(String專欄)

View Code

  說這麼多基本上差不多完了,下次清單+字典+元組就一起講了啊~ 

作者:毒逆天

出處:https://www.cnblogs.com/dotnetcrazy

打賞:<b>18i4JpL6g54yAPAefdtgqwRrZ43YJwAV5z</b>

本文版權歸作者和部落格園共有。歡迎轉載,但必須保留此段聲明,且在文章頁面明顯位置給出原文連接配接!