【Python編程:從入門到實踐】chapter2 變數和單一資料型別

來源:互聯網
上載者:User

標籤:沒有   birt   變數   大小   3.0   sage   1.5   字串   div   

2.1 運行
2.2 變數
message = "hello"
print(message)
2.2.1 變數的命名和使用
2.2.2 使用變數是避免命名錯誤
2.3 字串
“Hello”
‘Hello’
“Hello ‘zhaohu’”
‘this is "dog"! ‘

2.3.1 使用方法修改字串的大小寫
name = "My name is zhao"
print(name.title())
name.upper()
name.lower()

2.3.2 合并(拼接)字串
first_name = "zhaohu"
last_name = "hu"
full_name = first_name + " "+last_name
print(full_name)

2.3.3 使用定位字元或分行符號來添加空白
\t \n

2.3.4 刪除空白
rstrip();確保字串末尾沒有空格

2.3.5 使用字串時避免語法錯誤

message = "One of Python‘s strengths is its diverse community"
print(mssage)
此處的字串只能使用雙引號。

2.4 數字
2.4.1 整數
+ - * / **(乘方)

2.4.2 浮點數

2.4.3 使用函數str()避免類型錯誤
age = 23
message = "Happy" + str(age) + "rd Birthday"
print(message)

2.4.4 Python 2中的整數
3.0/2 = 1.5 3/2 = 1 (Python3: 3/2=1.5)

2.5 注釋
2.5.1 如何編寫注釋
# This is note

 

【Python編程:從入門到實踐】chapter2 變數和單一資料型別

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.