首页 > 后端开发 > Python教程 > 如何在Python中获取整数字面量属性而不是SyntaxError?

如何在Python中获取整数字面量属性而不是SyntaxError?

WBOY
发布: 2023-08-20 19:13:11
转载
1603 人浏览过

To get int literal attribute instead of SyntaxError, use a space or parenthesis. The int literal is a part if Numeric Literals in Python. Numeric Literals also includes the following four different numerical types −

  • int (signed integers) − They are often called just integers or ints, are positive or negative whole numbers with no decimal point.

  • long (long integers ) − Also called longs, they are integers of unlimited size, written like integers and followed by an uppercase or lowercase L.

  • 浮点数(浮点实数) - 也称为浮点数,它们表示实数,并且用小数点将整数部分和小数部分分隔开。浮点数也可以使用科学计数法表示,其中E或e表示10的幂次(2.5e2 = 2.5 x 102 = 250)。

  • complex (complex numbers) − are of the form a + bJ, where a and b are floats and J (or j) represents the square root of -1 (which is an imaginary number). The real part of the number is a, and the imaginary part is b. Complex numbers are not used much in Python programming.

Let’s see why and what is the syntax error discussed in this question −

语法错误:无效的十进制字面量

In this example, you can see we will get the invalid decimal literal syntax error −

print(5)
print(5.__class__)
登录后复制

输出

输出显示了一个语法错误

如何在Python中获取整数字面量属性而不是SyntaxError?

Let’s see how to fix it −

整数字面量属性

Example

的中文翻译为:

示例

这是我们可以通过使用空格或括号来解决整数字面值错误的方法 -

print(5)
print(5 .__class__)
print((5).__class__)
登录后复制

输出

5
<class 'int'>
<class 'int'>
登录后复制

Example

的中文翻译为:

示例

There’s another example as well −

a = 7
print(a)
print(a .__class__)
print((a).__class__)
登录后复制

输出

7
<class 'int'>
&t;class 'int'>
登录后复制

以上是如何在Python中获取整数字面量属性而不是SyntaxError?的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
来源:tutorialspoint.com
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板