程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Common data types in Python

編輯:Python

Common data types

Integer type -> int
Can represent a positive number 、 negative 、0 The representation of integers in different base numbers Decimal system -> Default base , No special indication is required Binary system -> With 0b start octal -> With 0o start Hexadecimal -> With 0x start Base number Basic numbers Several in a row Representation form Decimal system 0,1,2,3,4,5,6,7,8,91011 Binary system 0,120b11111111 octal 0,1,2,3,4,5,6,780o1544 Hexadecimal 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F160x11
# -----------python Data types commonly used in -----------
# Integers can be expressed as binary 、 octal 、 Decimal system 、 Hexadecimal
print(1)
print(0b11111111) # 2 Base number ,0b start
print(0o1544) # 8 Base number ,0o start
print(0xFFFF) # 16 Base number ,0x start
Floating point numbers -> float
Floating point numbers are composed of integer parts and decimal parts Floating point storage imprecision When calculating with floating-point numbers , The number of decimal places may be uncertain , Because the computer uses binary to store , Floating point numbers are stored imprecisely , There will be some errors
# Floating point numbers
print(1.1+2.2) # 3.300000000000003
print(1.1+2.1) # 3.2

resolvent

The import module decimal
from decimal import Decimal
print(Decimal('1.1')+Decimal('2.2'))

 

 
  Boolean type -> bool
A value used to indicate true or false True Express as true ,False Said the false Boolean values can be converted to integers True by 1,False by 0
# Boolean type
print(True+1) # 2
character string -> str
Strings are also called immutable character sequences You can use single quotes 、 Double quotes 、 Three quotation marks to indicate The string defined by single quotation marks and double quotation marks must be on one line A string defined by three quotation marks can be distributed on multiple consecutive lines
# character string
str1 = ' character string '
str2 = " String string string "
str3 = ''' character string
character string '''
print(str1, str2, str3)
 

 

 


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved