工具/原料
PYTHON 電腦
方法/步驟
1、打開JUPYTER NOTEBOOK,新建壹個PY文檔。
2、a = 'My name\'s peter'print(a)\'可以用在當壹個字符串是單引號的前提下,這樣PYTHON就不會出錯。
3、b = "This is what we call \"good\" things."print(b)\"這個情況是因為有雙引號,所以方法和上面的壹樣。
4、b = "This is what we call \"good" things."print(b)註意看這裏少了壹個\,所以就出錯了,因為字符串需要壹對引號。
5、c = "My name is Peter.\tYour name is Alice."print(c)\t可以使得該位置進行Tab,也就是連續4個空格。
6、d = "My name is Peter.\nYour name is Alice."print(d)\n是經常會用到的,用於換行。使得字符串看起來更加工整壹些。
7、e = "We are using \ in Windows."print(e)e = "We are using \\ in Windows."print(e)當字符串裏面我們需要表示\,那麽可以在前面再加壹個,形成\\,這樣會更加清晰。
8、f = 'I\'m Peter.\nMy name is Peter.'print(f)上面說的全部其實都可以用在同壹個字符串裏面,根據實際情況來運用。