Home > Backend Development > Python Tutorial > How to get integer literal properties in Python without SyntaxError?

How to get integer literal properties in Python without SyntaxError?

WBOY
Release: 2023-08-20 19:13:11
forward
1543 people have browsed it

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.

  • Floating Point Numbers (Floating Point Real Numbers) - Also known as floating point numbers, they represent real numbers with a decimal point separating the integer and decimal parts. Floating point numbers can also be represented using scientific notation, where E or e represents a power of 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 −

Syntax error: invalid decimal literal

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

print(5)
print(5.__class__)
Copy after login

Output

The output shows a syntax error

How to get integer literal properties in Python without SyntaxError?

Let’s see how to fix it −

Integer literal attribute

The Chinese translation of

Example

is:

Example

This is how we can solve the integer literal value error by using spaces or brackets -

print(5)
print(5 .__class__)
print((5).__class__)
Copy after login

Output

5
<class 'int'>
<class 'int'>
Copy after login
The Chinese translation of

Example

is:

Example

There’s another example as well −

a = 7
print(a)
print(a .__class__)
print((a).__class__)
Copy after login

Output

7
<class 'int'>
&t;class 'int'>
Copy after login

The above is the detailed content of How to get integer literal properties in Python without SyntaxError?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template