首頁  >  文章  >  後端開發  >  如何在Python中取得整數位面量屬性而不是SyntaxError?

如何在Python中取得整數位面量屬性而不是SyntaxError?

WBOY
WBOY轉載
2023-08-20 19:13:111525瀏覽

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刪除