Home >Backend Development >Python Tutorial >Reminiscing about Python basic data types
Free learning recommendation: python video tutorial
data Type is an essential attribute of every programming language. Only by assigning a clear data type to the data can the computer process the data. Therefore, it is very necessary to use the data type correctly. Different languages have similar data types, but the specific representation methods Different, the following are commonly used data types in Python programming:
Commonly used data types:
Integer type
The code is as follows (example):
print('十进制',118)print('二进制',0b10101111)print('八进制',0o176)print('十六进制',0x1EA3)
Floating point number type
The code is as follows (example):
n1 = 1.1n2 = 2.2print(n1+n2) 输出的结果是3.3000000000000003解决方案: 导入模块decimal from decimal import Decimalprint(Decimal('1.1') + Decimal('2.2')) 输出的结果是3.3
Boolean type
The code is as follows (example):
f1 = True f2 = Falseprint(f1+1) 输出的结果是2print(f2+1) 输出的结果是0
String type
The code is as follows (example):
str1 = '我还年轻,吃苦趁现在'str2 = "我还年轻,吃苦趁现在"str3 = """我还年轻,吃苦趁现在"""
Related free learning recommendations: python tutorial(Video)
The above is the detailed content of Reminiscing about Python basic data types. For more information, please follow other related articles on the PHP Chinese website!