Python基础教程:input()输入与数据类型转换
生活随笔
收集整理的這篇文章主要介紹了
Python基础教程:input()输入与数据类型转换
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
input就是個萬能輸入,不過input輸入的元素都是以str形式保存的,如果要他作為一個整數的話,就需要進行數據類型轉換。
input的使用
name=input('please input your name :\n') print(name) please input your name : 152 365 152 365 #這是個字符串name=input('please input your name :\n').split() print(name) please input your name : 152 365 ['152', '365'] #這是個list示例
''' 遇到問題沒人解答?小編創建了一個Python學習交流QQ群:778463939 尋找有志同道合的小伙伴,互幫互助,群里還有不錯的視頻學習教程和PDF電子書! ''' #輸入多個整數,輸出他們的十六進制 num=input('please input nums').split() for i in num:print(i,':',hex(int(i)))數據類型轉換
>>> int('123') 123 >>> float('12.34') 12.34 >>> int(12.34) 12 >>> float(12) 12.0 >>> str(1.23) '1.23' >>> str(100) '100' >>> bool(1) True >>> bool('') False總結
以上是生活随笔為你收集整理的Python基础教程:input()输入与数据类型转换的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 关于异常处理 try...
- 下一篇: Python基础教程:使用dict和se