Python程式設計從入門到實踐 基礎入門

2022-08-12 13:18:22 字數 1709 閱讀 9443

python程式設計從入門到實踐-------基礎入門

1、python中的變數

2、python首字母大寫使用title()方法,全部大寫upper()方法,全部小寫lower()方法

3、python中字串拼接使用 + 號

4、python中刪除字串的空格 刪除末尾空格的rstrip(),刪除開頭空格的lstrip(),刪除兩端空格的strip()

5、python2與python3的print區別:

6、python中整數運算,使用兩個乘號表示乘方運算

7、python中避免型別錯誤使用str()函式,將其他型別值轉化為字串

8、python中的注釋

1、python中的變數

變數名:大小寫英文,數字和下劃線的組合,不能以數字開頭

2、python首字母大寫使用title()方法,全部大寫upper()方法,全部小寫lower()方法

>>> name='ce shi python'

>>> name.title();

'ce shi python'

>>> print(name.upper())

ce shi python

>>> name2="ce shi python"

>>> print (name2.lower())

ce shi python12

3456

7893、python中字串拼接使用 + 號

>>> first_name='ce'

>>> last_name="shi"

>>> full_name=first_name + last_name

>>> print(full_name)

ceshi

>>> print("hello"+" "+full_name+" "+'welcome!')

hello ceshi welcome!12

3456

74、python中刪除字串的空格 刪除末尾空格的rstrip(),刪除開頭空格的lstrip(),刪除兩端空格的strip()

>>> best_language=" python "

>>> best_language = best_language.rstrip()

>>> best_language

' python'

>>> best_language = best_language.lstrip()

>>> best_language

'python'

>>> best_language=" python "

>>> best_language

' python '

>>> best_language.strip()

'python'12

3456

78910

1112

135、python2與python3的print區別:

python2中無需將要列印的內容放在括號內。python3中的print是乙個函式,因此括號必不可少;有些python2的print也包含括號。

6、python中整數運算,使用兩個乘號表示乘方運算

>>> 3**2 #(=3*3)

9>>> 10**3

100012

347、python中避免型別錯誤使用str(函式,將其他型別值轉化為字串

---------------------

Python 程式設計 從入門到實踐

1.官網安裝 3.環境配置 務必選中核取方塊add python to path 4.檢視 啟動python版本的命令 python 執行 print hello python world 5.終端執行x.py檔案 python x.py 7.檢視當前目錄中的所有檔案的命令 dir windows系...

Python程式設計 從入門到實踐 1

內容總結自 python程式設計 從入門到實踐 安裝python3 安裝文字編輯器sublime text並配置python3環境 安裝sublime text tools new build system 將 untitled.sublime build 文件中的所有內容刪除,輸入以下內容 注意,...

python程式設計 從入門到實踐 隨記

python程式設計 從入門到實踐 upper 全部大寫 lower 全部小寫 title 首字母大寫 rstrip 暫時性刪除末尾字元 預設空格 lstrip 暫時性刪除首部字元 預設空格 strip 暫時性刪除首尾字元 預設空格 len 列表元素數量 長度 pop 彈出 擠出 元素 remove...