1. 程式人生 > >Python的三種基本資料型別

Python的三種基本資料型別

數字
  • int(整型)
  • long(長整型),python對長整型沒有限制,理論上可以無限大。python3後沒有long了.
  • float
  字串   加了引號的都是字串。   單引號和雙引號沒有約束,儘量避免使用反斜槓轉移  
words = ‘Hi,this\’s my buddy’
words = "Hi,this’s my buddy”
  如果表達一段話的話只能用三個單引號或者雙引號,否則會報錯。   字串拼接:
 
In [1]: name = 'Edward'
 
In [2]: age = '27'
 
In [3]: name
Out[3]: 'Edward'
 
In [4]: age
Out[4]: '27'
 
In [5]: name + age
Out[5]: 'Edward27'
 
In [6]: name * 10
Out[6]: 'EdwardEdwardEdwardEdwardEdwardEdwardEdwardEdwardEdwardEdward'
  PS:字串只能和字串進行拼接,不能跨資料型別   布林值
 
  • True(真)
  • False(假)
  值得一提的是python中None和0都是False