大家好,欢迎来到IT知识分享网。
今天我们开始学习Python基础,第一部分内容是数据类型和数字类型。
Today we start learning Python basics, the first part of which is about data types and number types.
01
数据类型
Python支持丰富的数据类型,其中标准的数据类型有以下六个:
(1)Number(数字),如1,-2,3.0,5+6j
(2)String(字符串),如’Internet’,”长城”
(3)List(列表),如[1,2,3],[“Spring”,”Summer”,”Autumn”]
(4)Tuple(元组),如(1,3,5),(”大学”,”中学”,”小学”)
(5)Dictionary(字典),如{1:”优秀”,2:”良好”,3:”合格”}
(6)Set(集合),如{“成功”,”失败”}
其中,Number(数字),String(字符串),Tuple(元组)为不可变类型数据。不可变类型数据一旦生成,可以使用,但不能修改。List(列表),Dictionary(字典),Set(集合)为可变类型数据。除此以外,python还支持一种特殊的数据类型,即空类型(NoneType),其值为None。None不是0也不是空字符串,表示什么也没有,是一个空对象。
Python supports a rich set of data types, of which the following six are standard.
(1) Number (numbers), such as 1, -2, 3.0, 5+6j
(2) String (string), such as ‘Internet’, “The Great Wall”
(3) List (list), such as [1,2,3], [“Spring”, “Summer”, “Autumn”]
(4) Tuple (tuple), such as (1,3,5), (“University”, “Secondary”, “Primary”)
(5) Dictionary (dictionary), such as {1: “excellent”, 2: “good”, 3: “pass”}
(6) Set (set), such as {“success”, “failure”}
Among them, Number (number), String (string), Tuple (tuple) are immutable types of data. List, Dictionary, and Set are mutable types of data. In addition to these, python supports a special data type, the NoneType, whose value is None. none is neither 0 nor an empty string, and means nothing, an empty object.
02
数字类型
Python支持四种常见的数字类型:整型(Int),浮点(Float)类型,复数(Complex)类型和布尔(Bool)类型。
(1)整型:整数可以是二进制,八进制,十进制和十六进制整数。
十进制:使用0-9共10个数字表示
二进制:只需用两个数字(0和1)表示,以0B或0b开头
八进制:需要用8个数字(0-7)表示,以0o或0O开头
十六进制:需要用16个数字(0-F)表示,以0x或0X开头
(2)浮点类型
浮点类型的数包括整数部分和小数部分,可以写成十进制形式或用科学计数法表示。
使用round(f,n)函数限定小数位数为n位
(3)复数类型
复数由实部和虚部构成,可以用a+bj或a+bJ或complex(a,b)表示。可用z.real获取实部,z.imag获取虚部。
(4)布尔类型
布尔类型的常量包括True和False,分别表示真和假。
Python supports four common types of numbers: integer (Int), float, complex, and boolean.
(1) Integer: Integers can be binary, octal, decimal, and hexadecimal integers.
Decimal: 10 digits from 0-9 are used to represent
Binary: only two digits (0 and 1) are required, starting with 0B or 0b
Octal: need to use 8 numbers (0-7), starting with 0o or 0O
Hexadecimal: need to use 16 numbers (0-F), starting with 0x or 0X
(2) floating point type
floating-point type of numbers, including the integer part and the decimal part, can be written in decimal form or expressed in scientific notation.
The use of round (f, n) function to limit the number of decimal places for n bits
(3) the type of complex numbers
complex numbers by the real part and the imaginary part of the composition, you can use a + bj or a + bJ or complex (a, b) that. The real part can be obtained by z.real and the imaginary part by z.imag.
(4) Boolean type
The constants of Boolean type include True and False, which represent true and false respectively.
参考资料:文字:百度;图片:微博;翻译:百度翻译
本文由LearningYard新学苑原创,部分图片文字来自网络,如有侵权请联系。
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/59111.html