python系列------輸入輸出

來源:互聯網
上載者:User

標籤:python   字串   please   star   

輸入

x = 3

print(x)

age=input(“please input string:”)

input函數的使用

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/6F/F4/wKioL1WuYASg776CAAFbPjcNOrU547.jpg" title="1.png" alt="wKioL1WuYASg776CAAFbPjcNOrU547.jpg" />

input函數是讀取的字串,不可以當做整形來使用

【樣本】

star=input(‘input your age:’)

當你輸入一個數字時比如是22,你再通過賦值是不可以的

age=age+1

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/6F/F4/wKioL1WuYD3QnCLfAADYtxKzCYo103.jpg" title="2.png" alt="wKioL1WuYD3QnCLfAADYtxKzCYo103.jpg" />

如上提示,表示age是string沒有int的功能

由此可見,通過函數input()輸入的內容是string

1.1    輸出

print()函數,直接列印輸出

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/6F/F8/wKiom1WuXreRzcqaAACsUY9E0c8862.jpg" title="3.png" alt="wKiom1WuXreRzcqaAACsUY9E0c8862.jpg" />

格式輸出

在print()函數中再去調用format()函數

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/6F/F8/wKiom1WuXuLDE12cAABfoHQ-ww4242.jpg" title="4.png" alt="wKiom1WuXuLDE12cAABfoHQ-ww4242.jpg" />

如果想輸出整形可以調用python的內建函數int()

age=int(age)

age=age+1

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/6F/F4/wKioL1WuYOaj13KcAAAmN4d_Gug172.jpg" title="5.png" alt="wKioL1WuYOaj13KcAAAmN4d_Gug172.jpg" />

本文出自 “技術博” 部落格,謝絕轉載!

python系列------輸入輸出

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.