基本数据类型python

Now you know how to interact with the Python interpreter and execute Python code. It’s time to dig into the Python language. First up is a discussion of the basic data types that are built into Python.

现在,您知道如何与Python解释器进行交互并执行Python代码 。 现在是时候深入研究Python语言了。 首先是对Python内置的基本数据类型的讨论。

Here’s what you’ll learn in this tutorial:

这是您将在本教程中学到的内容:

  • You’ll learn about several basic numeric, string, and Boolean types that are built into Python. By the end of this tutorial, you’ll be familiar with what objects of these types look like, and how to represent them.
  • You’ll also get an overview of Python’s built-in functions. These are pre-written chunks of code you can call to do useful things. You have already seen the built-in print() function, but there are many others.
  • 您将了解Python内置的几种基本数字,字符串布尔类型。 在本教程结束时,您将熟悉这些类型的对象的外观以及如何表示它们。
  • 您还将获得Python内置函数的概述 这些是预先编写的代码块,您可以调用它们来做有用的事情。 您已经看过内置的print()函数,但还有许多其他功能。

Get Notified: Don’t miss the follow up to this tutorial—Click here to join the Real Python Newsletter and you’ll know when the next instalment comes out.

通知您:不要错过本教程的后续内容- 单击此处加入Real Python Newslet ,您将知道下一期的发行时间。

整数 (Integers)

In Python 3, there is effectively no limit to how long an integer value can be. Of course, it is constrained by the amount of memory your system has, as are all things, but beyond that an integer can be as long as you need it to be:

在Python 3中,整数值的有效长度实际上没有限制。 当然,它受系统以及所有事物的内存量的限制,但除此之外,整数可以是您需要的整数,只要它是:

 >>> >>>  printprint (( 123123123123123123123123123123123123123123123123 123123123123123123123123123123123123123123123123 + + 11 )
)
123123123123123123123123123123123123123123123124
123123123123123123123123123123123123123123123124

Python interprets a sequence of decimal digits without any prefix to be a decimal number:

Python将不含任何前缀的十进制数字序列解释为十进制数字:

The following strings can be prepended to an integer value to indicate a base other than 10:

可以将以下字符串添加为整数值,以表示除10以外的底数:

Prefix 字首 Interpretation 解释 Base 基础
0b (zero + lowercase letter 0b (零+小写字母'b')'b'

0B (zero + uppercase letter 0B (零+大写字母'B')'B'

Binary 二元 2 2
0o (zero + lowercase letter 0o (零+小写字母'o')'o'

0O (zero + uppercase letter 0O (零+大写字母'O')'O'

Octal 八进制 8 8
0x (zero + lowercase letter 0x (零+小写字母'x')'x'

0X (zero + uppercase letter 0X (零+大写字母'X')'X'

Hexadecimal 十六进制 16 16

For example:

例如:

 >>> >>>  printprint (( 00 o10o10 )
)
88>>> >>>  printprint (( 0x100x10 )
)
1616>>> >>>  printprint (( 0b100b10 )
)
2
2

For more information on integer values with non-decimal bases, see the following Wikipedia sites: Binary, Octal, and Hexadecimal.

有关具有非十进制基数的整数值的更多信息,请参见以下Wikipedia网站: Binary , Octal和Hexadecimal 。

The underlying type of a Python integer, irrespective of the base used to specify it, is called int:

不管用来指定它的基数如何,Python整数的基础类型都称为int

Note: This is a good time to mention that if you want to display a value while in a REPL session, you don’t need to use the print() function. Just typing the value at the >>> prompt and hitting Enter will display it:

注意:这是提提您在REPL会话中显示值的好时机,不需要使用print()函数。 只需在>>>提示符下键入值,然后按Enter即可显示它:

 >>> >>>  10
10
10
10
>>> >>>  0x10
0x10
16
16
>>> >>>  0b10
0b10
2
2

Many of the examples in this tutorial series will use this feature.

本教程系列中的许多示例都将使用此功能。

Note that this does not work inside a script file. A value appearing on a line by itself in a script file will not do anything.

请注意,这在脚本文件中不起作用。 脚本文件中一行单独显示的值不会执行任何操作。

浮点数字 (Floating-Point Numbers)

The float type in Python designates a floating-point number. float values are specified with a decimal point. Optionally, the character e or E followed by a positive or negative integer may be appended to specify scientific notation:

Python中的float类型指定浮点数。 float值用小数点指定。 可选地,可以在字符eE后跟一个正整数或负整数,以指定科学计数法 :

侧边栏:浮点表示 (Sidebar: Floating-Point Representation)

The following is a bit more in-depth information on how Python represents floating-point numbers internally. You can readily use floating-point numbers in Python without understanding them to this level, so don’t worry if this seems overly complicated. The information is presented here in case you are curious.

以下是有关Python如何在内部表示浮点数的更深入的信息。 您可以很容易地在Python中使用浮点数,而无需了解它们到这个水平,因此如果这看起来过于复杂,请不要担心。 如果您感到好奇,请在此处显示信息。

Almost all platforms represent Python float values as 64-bit “double-precision” values, according to the IEEE 754 standard. In that case, the maximum value a floating-point number can have is approximately 1.8 ⨉ 10308. Python will indicate a number greater than that by the string inf:

根据IEEE 754标准,几乎所有平台都将Python float值表示为64位“双精度”值。 在这种情况下,浮点数可以具有的最大值约为1.8×10 308 。 Python将通过字符串inf指示大于该数字的数字:

 1.79e308
1.79e308
1.79e+308
1.79e+308
1.8e308
1.8e308
inf
inf

The closest a nonzero number can be to zero is approximately 5.0 ⨉ 10-324. Anything closer to zero than that is effectively zero:

一个非零数字可以最接近零的近似值是5.0×10 -324 。 接近零的任何东西实际上都是零:

 5e-324
5e-324
5e-324
5e-324
1e-325
1e-325
0.0
0.0

Floating point numbers are represented internally as binary (base-2) fractions. Most decimal fractions cannot be represented exactly as binary fractions, so in most cases the internal representation of a floating-point number is an approximation of the actual value. In practice, the difference between the actual value and the represented value is very small and should not usually cause significant problems.

浮点数在内部以二进制(基2)分数表示。 大多数十进制小数不能完全表示为二进制小数,因此在大多数情况下,浮点数的内部表示是实际值的近似值。 在实践中,实际值与代表值之间的差异很小,通常不应引起重大问题。

Further Reading: For additional information on floating-point representation in Python and the potential pitfalls involved, see Floating Point Arithmetic: Issues and Limitations in the Python documentation.

进一步阅读:有关Python中浮点表示形式以及涉及的潜在陷阱的更多信息,请参见Python文档中的浮点算法:问题和局限性 。

复数 (Complex Numbers)

Complex numbers are specified as <real part>+<imaginary part>j. For example:

复数指定为<real part>+<imaginary part>j 。 例如:

 >>> >>>  22 ++ 3j
3j
(2+3j)
(2+3j)
>>> >>>  typetype (( 22 ++ 3j3j )
)
<class 'complex'>
<class 'complex'>

弦乐 (Strings)

Strings are sequences of character data. The string type in Python is called str.

字符串是字符数据的序列。 Python中的字符串类型称为str

String literals may be delimited using either single or double quotes. All the characters between the opening delimiter and matching closing delimiter are part of the string:

字符串文字可以使用单引号或双引号分隔。 开头定界符和匹配的结束定界符之间的所有字符都是字符串的一部分:

A string in Python can contain as many characters as you wish. The only limit is your machine’s memory resources. A string can also be empty:

Python中的字符串可以包含任意多个字符。 唯一的限制是计算机的内存资源。 字符串也可以为空:

 >>> >>>  ''
''
''
''

What if you want to include a quote character as part of the string itself? Your first impulse might be to try something like this:

如果要在字符串本身中包含引号字符怎么办? 您的第一冲动可能是尝试这样的事情:

As you can see, that doesn’t work so well. The string in this example opens with a single quote, so Python assumes the next single quote, the one in parentheses which was intended to be part of the string, is the closing delimiter. The final single quote is then a stray and causes the syntax error shown.

如您所见,这并不是很好。 此示例中的字符串以单引号引起来,因此Python假定下一个单引号(作为括号的一部分,该括号应作为字符串的一部分)是结束定界符。 最后的单引号是一个流浪,并导致显示语法错误。

If you want to include either type of quote character within the string, the simplest way is to delimit the string with the other type. If a string is to contain a single quote, delimit it with double quotes and vice versa:

如果要在字符串中包括两种引号字符,则最简单的方法是用另一种类型来分隔字符串。 如果字符串包含单引号,则用双引号将其定界,反之亦然:

 >>> >>>  printprint (( "This string contains a single quote (') character.""This string contains a single quote (') character." )
)
This string contains a single quote (') character.This string contains a single quote (') character.>>> >>>  printprint (( 'This string contains a double quote (") character.''This string contains a double quote (") character.' )
)
This string contains a double quote (") character.
This string contains a double quote (") character.

字符串中的转义序列 (Escape Sequences in Strings)

Sometimes, you want Python to interpret a character or sequence of characters within a string differently. This may occur in one of two ways:

有时,您希望Python对字符串中的字符或字符序列进行不同的解释。 这可能以两种方式之一发生:

  • You may want to suppress the special interpretation that certain characters are usually given within a string.
  • You may want to apply special interpretation to characters in a string which would normally be taken literally.
  • 您可能想抑制特殊解释,即某些字符通常在字符串中给出。
  • 您可能想对字符串中的字符应用特殊的解释,这通常会从字面上理解。

You can accomplish this using a backslash () character. A backslash character in a string indicates that one or more characters that follow it should be treated specially. (This is referred to as an escape sequence, because the backslash causes the subsequent character sequence to “escape” its usual meaning.)

您可以使用反斜杠( )字符。 字符串中的反斜杠字符表示应特别对待其后的一个或多个字符。 (这被称为转义序列,因为反斜杠导致后续字符序列“转义”其通常的含义。)

Let’s see how this works.

让我们看看它是如何工作的。

禁止特殊字符含义 (Suppressing Special Character Meaning)

You have already seen the problems you can come up against when you try to include quote characters in a string. If a string is delimited by single quotes, you can’t directly specify a single quote character as part of the string because, for that string, the single quote has special meaning—it terminates the string:

您已经看到了尝试在字符串中包含引号字符时可能遇到的问题。 如果字符串由单引号引起来,则不能直接将单引号字符指定为字符串的一部分,因为对于该字符串,单引号具有特殊含义-它终止字符串:

Specifying a backslash in front of the quote character in a string “escapes” it and causes Python to suppress its usual special meaning. It is then interpreted simply as a literal single quote character:

在字符串中的引号字符前面指定反斜杠可以使它“转义”,并导致Python取消其通常的特殊含义。 然后将其简单地解释为文字单引号字符:

 >>> >>>  printprint (( 'This string contains a single quote ('This string contains a single quote ( '' ) character.') character.' )
)
This string contains a single quote (') character.
This string contains a single quote (') character.

The same works in a string delimited by double quotes as well:

同样在用双引号分隔的字符串中也起作用:

The following is a table of escape sequences which cause Python to suppress the usual special interpretation of a character in a string:

下表是转义序列的表,这些转义序列使Python禁止对字符串中的字符进行通常的特殊解释:

Escape
Sequence
逃逸
序列
Usual Interpretation of
Character(s) After Backslash
通常的解释
反斜杠后的字符
“Escaped” Interpretation “逃脱”的解释
'' Terminates string with single quote opening delimiter 用单引号分隔符终止字符串 ') character' )字符
"" Terminates string with double quote opening delimiter 用双引号分隔符终止字符串 ") character" )字符
newlinenewline Terminates input line 终止输入线 Newline is ignored 换行符被忽略
Introduces escape sequence 介绍转义序列 Literal backslash () character 文字反斜线( )字符

Ordinarily, a newline character terminates line input. So pressing Enter in the middle of a string will cause Python to think it is incomplete:

通常,换行符会终止行输入。 因此,在字符串中间按Enter键会使Python认为它不完整:

 >>> >>>  printprint (( 'a'aSyntaxError: EOL while scanning string literal
SyntaxError: EOL while scanning string literal

To break up a string over more than one line, include a backslash before each newline, and the newlines will be ignored:

要在多行中分解一个字符串,请在每个换行符前添加一个反斜杠,并且这些换行符将被忽略:

To include a literal backslash in a string, escape it with a backslash:

要在字符串中包含文字反斜杠,请使用反斜杠对其进行转义:

 >>> >>>  printprint (( 'foo'foo  bar'bar' )
)
foobar
foobar

对字符应用特殊含义 (Applying Special Meaning to Characters)

Next, suppose you need to create a string that contains a tab character in it. Some text editors may allow you to insert a tab character directly into your code. But many programmers consider that poor practice, for several reasons:

接下来,假设您需要创建一个包含制表符的字符串。 某些文本编辑器可能允许您将制表符直接插入代码中。 但是许多程序员认为这种做法很差,原因有以下几点:

  • The computer can distinguish between a tab character and a sequence of space characters, but you can’t. To a human reading the code, tab and space characters are visually indistinguishable.
  • Some text editors are configured to automatically eliminate tab characters by expanding them to the appropriate number of spaces.
  • Some Python REPL environments will not insert tabs into code.
  • 计算机可以区分制表符和空格字符,但是不能。 对于阅读代码的人来说,制表符和空格字符在视觉上是无法区分的。
  • 某些文本编辑器配置为通过将制表符字符扩展到适当的空格数来自动消除制表符。
  • 某些Python REPL环境不会在代码中插入制表符。

In Python (and almost all other common computer languages), a tab character can be specified by the escape sequence t:

在Python(以及几乎所有其他常见的计算机语言)中,可以使用转义序列t指定制表符:

The escape sequence t causes the t character to lose its usual meaning, that of a literal t. Instead, the combination is interpreted as a tab character.

转义序列t导致t字符失去其通常的含义,即文字t 。 而是将组合解释为制表符。

Here is a list of escape sequences that cause Python to apply special meaning instead of interpreting literally:

这是导致Python应用特殊含义而不是逐字解释的转义序列的列表:

Escape Sequence 转义序列 “Escaped” Interpretation “逃脱”的解释
aa BEL) characterBEL )字符
bb BS) characterBS )字符
ff FF) characterFF )字符
nn LF) characterLF )字符
N{<name>}N{<name>} <name><name>字符
rr CR) characterCR )字符
tt TAB) characterTAB )字符
uxxxxuxxxx xxxxxxxx Unicode字符
UxxxxxxxxUxxxxxxxx xxxxxxxxxxxxxxxx Unicode字符
vv VT) characterVT )字符
oooooo oooooo
xhhxhh hhhh字符

Examples:

例子:

 >>> >>>  printprint (( "a"a tt b"b" )
)
a    b
a    b
>>> >>>  printprint (( "a"a 141x61141x61 "" )
)
aaa
aaa
>>> >>>  printprint (( "a"a nn b"b" )
)
a
a
b
b
>>> >>>  printprint (( '' u2192u2192    N{rightwards arrow}N{rightwards arrow} '' )
)
→ →
→ →

This type of escape sequence is typically used to insert characters that are not readily generated from the keyboard or are not easily readable or printable.

这种类型的转义序列通常用于插入不容易从键盘生成或不易于阅读或打印的字符。

原始字符串 (Raw Strings)

A raw string literal is preceded by r or R, which specifies that escape sequences in the associated string are not translated. The backslash character is left in the string:

原始字符串文字以rR ,该rR指定不转换关联字符串中的转义序列。 反斜杠字符留在字符串中:

三重引用的字符串 (Triple-Quoted Strings)

There is yet another way of delimiting strings in Python. Triple-quoted strings are delimited by matching groups of three single quotes or three double quotes. Escape sequences still work in triple-quoted strings, but single quotes, double quotes, and newlines can be included without escaping them. This provides a convenient way to create a string with both single and double quotes in it:

在Python中还有另一种定界字符串的方法。 三引号字符串由匹配的三个单引号或三个双引号的组分隔。 转义序列仍然可以用三引号引起来,但可以包含单引号,双引号和换行符而不必转义。 这提供了一种创建带有单引号和双引号的字符串的便捷方法:

 >>> >>>  printprint (( '''This string has a single (') and a double (") quote.''''''This string has a single (') and a double (") quote.''' )
)
This string has a single (') and a double (") quote.
This string has a single (') and a double (") quote.

Because newlines can be included without escaping them, this also allows for multiline strings:

由于可以包含换行符而无需转义它们,因此这也允许使用多行字符串:

You will see in the upcoming tutorial on Python Program Structure how triple-quoted strings can be used to add an explanatory comment to Python code.

您将在即将到来的有关Python程序结构的教程中看到如何使用三引号引起来的字符串向Python代码添加解释性注释。

布尔类型,布尔上下文和“真实性” (Boolean Type, Boolean Context, and “Truthiness”)

Python 3 provides a Boolean data type. Objects of Boolean type may have one of two values (True or False):

Python 3提供了布尔数据类型。 布尔类型的对象可能具有两个值之一( TrueFalse ):

 >>> >>>  typetype (( TrueTrue )
)
<class 'bool'>
<class 'bool'>
>>> >>>  typetype (( FalseFalse )
)
<class 'bool'>
<class 'bool'>

As you will see in upcoming tutorials, expressions in Python are often evaluated in Boolean context, meaning they are interpreted to represent truth or falsehood. A value that is true in Boolean context is sometimes said to be “truthy,” and one that is false in Boolean context is said to be “falsy.” (You may also see “falsy” spelled “falsey.”)

正如您将在即将到来的教程中看到的那样,Python中的表达式通常在布尔上下文中求值,这意味着它们被解释为代表真假。 在布尔上下文中为true的值有时被称为“真值”,在布尔上下文中为false的值有时被称为“虚假”。 (您可能还会看到“ falsy”拼写为“ falsey”。)

The “truthiness” of an object of Boolean type is self-evident: Boolean objects that are equal to True are truthy (true), and those equal to False are falsy (false). But non-Boolean objects can be evaluated in Boolean context as well and determined to be true or false.

布尔类型对象的“真实性”是不言而喻的:等于True布尔对象是True的(true),等于False布尔对象是False的(false)。 但是,也可以在布尔上下文中评估非布尔对象,并将其确定为true或false。

You will learn more about evaluation of objects in Boolean context when you encounter logical operators in the upcoming tutorial on operators and expressions in Python.

在即将到来的Python运算符和表达式教程中,当您遇到逻辑运算符时,您将学到更多关于布尔上下文中对象评估的知识。

内建功能 (Built-In Functions)

The Python interpreter supports many functions that are built-in: sixty-eight, as of Python 3.6. You will cover many of these in the following discussions, as they come up in context.

Python解释器支持许多内置功能:从Python 3.6开始为68。 在上下文中,您将在以下讨论中涵盖其中的许多内容。

For now, a brief overview follows, just to give a feel for what is available. See the Python documentation on built-in functions for more detail. Many of the following descriptions refer to topics and concepts that will be discussed in future tutorials.

现在,将进行简要概述,以使您对现有功能有所了解。 有关更多详细信息,请参见内置函数的Python文档 。 以下许多描述都涉及将在以后的教程中讨论的主题和概念。

数学 (Math)

Function 功能 Description 描述
abs()abs() Returns absolute value of a number 返回数字的绝对值
divmod()divmod() Returns quotient and remainder of integer division 返回商和整数除法的余数
max()max() Returns the largest of the given arguments or items in an iterable 返回最大的给定参数或可迭代项
min()min() Returns the smallest of the given arguments or items in an iterable 返回给定参数或可迭代项中的最小项
pow()pow() Raises a number to a power 幂数
round()round() Rounds a floating-point value 四舍五入浮点值
sum()sum() Sums the items of an iterable 总结一个可迭代的项目

类型转换 (Type Conversion)

Function 功能 Description 描述
ascii()ascii() Returns a string containing a printable representation of an object 返回包含对象的可打印表示形式的字符串
bin()bin() Converts an integer to a binary string 将整数转换为二进制字符串
bool()bool() Converts an argument to a Boolean value 将参数转换为布尔值
chr()chr() Returns string representation of character given by integer argument 返回整数参数给出的字符的字符串表示形式
complex()complex() Returns a complex number constructed from arguments 返回根据参数构造的复数
float()float() Returns a floating-point object constructed from a number or string 返回由数字或字符串构造的浮点对象
hex()hex() Converts an integer to a hexadecimal string 将整数转换为十六进制字符串
int()int() Returns an integer object constructed from a number or string 返回由数字或字符串构造的整数对象
oct()oct() Converts an integer to an octal string 将整数转换为八进制字符串
ord()ord() Returns integer representation of a character 返回字符的整数表示
repr()repr() Returns a string containing a printable representation of an object 返回包含对象的可打印表示形式的字符串
str()str() Returns a string version of an object 返回对象的字符串版本
type()type() Returns the type of an object or creates a new type object 返回对象的类型或创建一个新的类型对象

可迭代和迭代器 (Iterables and Iterators)

Function 功能 Description 描述
all()all() True if all elements of an iterable are trueTrue
any()any() Returns True if any elements of an iterable are true 如果iterable的任何元素为True则返回True
enumerate()enumerate() Returns a list of tuples containing indices and values from an iterable 返回包含可迭代对象的索引和值的元组列表
filter()filter() Filters elements from an iterable 从可迭代元素中过滤元素
iter()iter() Returns an iterator object 返回一个迭代器对象
len()len() Returns the length of an object 返回对象的长度
map()map() Applies a function to every item of an iterable 将函数应用于可迭代的每个项目
next()next() Retrieves the next item from an iterator 从迭代器中检索下一项
range()range() Generates a range of integer values 生成整数范围
reversed()reversed() Returns a reverse iterator 返回反向迭代器
slice()slice() slice objectslice对象
sorted()sorted() Returns a sorted list from an iterable 从迭代器返回排序列表
zip()zip() Creates an iterator that aggregates elements from iterables 创建一个迭代器,该迭代器聚合可迭代对象中的元素

复合数据类型 (Composite Data Type)

Function 功能 Description 描述
bytearray()bytearray() bytearray classbytearray类的对象
bytes()bytes() bytes object (similar to bytes对象(类似于bytearray, but immutable)bytearray ,但不可变)
dict()dict() dict objectdict对象
frozenset()frozenset() frozenset objectfrozenset对象
list()list() list objectlist对象
object()object() Returns a new featureless object 返回一个新的无特征对象
set()set() set objectset对象
tuple()tuple() tuple objecttuple对象

类,属性和继承 (Classes, Attributes, and Inheritance)

Function 功能 Description 描述
classmethod()classmethod() Returns a class method for a function 返回函数的类方法
delattr()delattr() Deletes an attribute from an object 从对象中删除属性
getattr()getattr() Returns the value of a named attribute of an object 返回对象的命名属性的值
hasattr()hasattr() True if an object has a given attributeTrue
isinstance()isinstance() Determines whether an object is an instance of a given class 确定对象是否是给定类的实例
issubclass()issubclass() Determines whether a class is a subclass of a given class 确定一个类是否是给定类的子类
property()property() Returns a property value of a class 返回类的属性值
setattr()setattr() Sets the value of a named attribute of an object 设置对象的命名属性的值
super()super() Returns a proxy object that delegates method calls to a parent or sibling class 返回将方法调用委托给父类或同级类的代理对象

输入输出 (Input/Output)

Function 功能 Description 描述
format()format() Converts a value to a formatted representation 将值转换为格式表示
input()input() Reads input from the console 从控制台读取输入
open()open() Opens a file and returns a file object 打开文件并返回文件对象
print()print() Prints to a text stream or the console 打印到文本流或控制台

变量,引用和范围 (Variables, References, and Scope)

Function 功能 Description 描述
dir()dir() Returns a list of names in current local scope or a list of object attributes 返回当前本地范围内的名称列表或对象属性列表
globals()globals() Returns a dictionary representing the current global symbol table 返回代表当前全局​​符号表的字典
id()id() Returns the identity of an object 返回对象的标识
locals()locals() Updates and returns a dictionary representing current local symbol table 更新并返回代表当前本地符号表的字典
vars()vars() __dict__ attribute for a module, class, or object__dict__属性

杂 (Miscellaneous)

Function 功能 Description 描述
callable()callable() True if object appears callableTrue
compile()compile() Compiles source into a code or AST object 将源代码编译成代码或AST对象
eval()eval() Evaluates a Python expression 评估Python表达式
exec()exec() Implements dynamic execution of Python code 实现Python代码的动态执行
hash()hash() Returns the hash value of an object 返回对象的哈希值
help()help() Invokes the built-in help system 调用内置的帮助系统
memoryview()memoryview() Returns a memory view object 返回一个内存视图对象
staticmethod()staticmethod() Returns a static method for a function 返回函数的静态方法
__import__()__import__() import statementimport语句调用

结论 (Conclusion)

In this tutorial, you learned about the built-in data types and functions Python provides.

在本教程中,您了解了Python提供的内置数据类型功能

The examples given so far have all manipulated and displayed only constant values. In most programs, you are usually going to want to create objects that change in value as the program executes.

到目前为止给出的示例都已操纵并仅显示恒定值。 在大多数程序中,通常需要创建随程序执行而值改变的对象。

Head to the next tutorial to learn about Python variables.

前往下一个教程,了解Python 变量。

Don’t miss the follow up tutorial: Click here to join the Real Python Newsletter and you’ll know when the next instalment comes out.

不要错过后续教程: 单击此处加入Real Python Newslet ,您将知道下一期的发行时间。

« Interacting with Python«与Python交互
Basic Data Types in PythonPython中的基本数据类型
Variables in Python »Python中的变量»



[ Improve Your Python With

基本数据类型python_Python中的基本数据类型相关推荐

  1. php变量与数据类型,php中变量与数据类型讲解

    本文主要和大家分享一些PHP基础知识,php中变量与数据类型讲解,希望能帮助到大家. 1.什么是变量 变量就相当于一个口袋,可以往里面存放东西. 在编程语言里面,变量是用来存放数值的. 2. PHP如 ...

  2. java中的基本数据类型_Java中的基本数据类型和引用数据类型

    数据类型用于帮助确定变量可存放的一组值,以及可对这组特定值执行的操作.Java提供了在所有平台上都普遍支持的多种数据类型. 一.基本数据类型 byte:Java中最小的数据类型,在内存中占8位(bit ...

  3. mysql sql查询json数据类型_SQL中的JSON数据类型

    SQL中的JSON数据类型 概述 MySQL支持原生JSON类型,使用JSON数据类型相较于将JSON格式的字符串存储在String型中的优势有: 存储时会自动验证JSON文本: 可以优化存储格式.存 ...

  4. java中最基本的数据类型,java中的基本数据类型

    java中的基本数据类型 java的基本数据类型以及长度如下: 1.整数型 字节型byte:占1个字节 范围为 -28-1至28-1-1 短整型short:占2个字节 范围为 -22*8-1 至 22 ...

  5. python中常见的数据类型_Python中常见的数据类型总结(四)

    三 集合(set) dict是建立了一系列的映射关系,而set是建立一系列无序的,不重复的元素. 1创建 创建set的方式是调用set()并传入一个list,list的元素将作为set的元素. > ...

  6. python常见的数据类型_Python中常见的数据类型总结

    Python提供多种数据类型来存放数据项集合,主要包括序列(列表list和元组tuple),映射(如字典dict),集合(set),下面对这几种一一介绍: 一 序列 1.列表list 列表是一种有序的 ...

  7. python数据类型-Python3中六种标准数据类型的简单说明和理解

    作者:心叶 时间:2018-04-21 09:28 Python 中的变量不需要声明.每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建. Python3 中有六个标准的数据类型:Number( ...

  8. 比double精度更高的数据类型_MATLAB中图像的数据类型

    一.几种图象的数据类型. 表中罗列了常见的数据类型及其含义: 输入图像,指定为数值标量.向量.矩阵或多维数组. 1.如果 I 是灰度或真彩色 (RGB) 图像,它可以是 uint8.uint16.do ...

  9. 说出java中基本数据类型_java中的基本数据类型

    1.整数: byte 1个字节   -128到127 short 2个字节 -32,768到32,767 int    4个字节  -2,147,483,648到2,147,483,647 long  ...

最新文章

  1. Kali Linux python 安装pip
  2. 模板模式(TemplateMethod)和策略(StrategyMethod)模式
  3. Tomcat配置Web虚拟目录
  4. 开发者社区精选直播合集一览
  5. python 找到目录下文件名规则_Python学习第162课--PATH变量值修改以及模糊查找文件名...
  6. 计算机二级 java和web_2020年全国计算机二级WEB程序复习知识点:JavaBean
  7. MySQL安装 - Linux7下. rpm方式安装
  8. 细谈Web框架设计与实现
  9. 递归列出文件下的文件信息,迭代器
  10. SQL执行效率提升几万倍的操作详解!
  11. JavaScript:变量提升作用域
  12. CentOs 开启ssh服务
  13. 两人共用计算机,双人共享一台电脑主机 两个人同时使用一台电脑主机
  14. 抖音上很火的3D立体动态相册实现代码!
  15. 功能安全标准-ISO26262-6---硬件集成测试
  16. 实验——田忌赛马c++
  17. 使用DDE传输数据至SQL Server
  18. 云计算、大数据和人工智能之间的关系
  19. 线上英语教学APP开源平台(定制制作)
  20. 英语3500词(十)adventure主题(2022.1.22)

热门文章

  1. 创客路上,跟着嘻多猴快乐出发!
  2. 043-云E办_后端项目总结
  3. 英语文档学习颗粒归仓
  4. pip 下载慢——解决方法
  5. js动态修改css样式
  6. 阿里技术专家:技术人员如何快速成长,实现职场跃迁?14页ppt干货分享
  7. 事业单位计算机操作专业技术分析面试题,事业单位面试:历年面试试题解析(四)...
  8. javaweb课程设计音乐播放网
  9. 字节算法题--N阶台阶,每次走一步或两步,计算共有多少种走法,并将每种走法打印出来。
  10. 4-3 使用函数计算两个复数之积 (10分)