Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Numeric Types | Numeric Types
Python Data Types

book
Numeric Types

Let's start our acquaintance with the simplest and most popular data type - numeral. But what is it? A numeric data type is a data type that stores numbers. It is worth noting that this data type is immutable - that is, if we have already defined a variable as a number, we will no longer be able to change this variable unless we redefine it.

There are three numeric types in Python:

  • integers,
  • floating point numbers,
  • and of course the complex numbers.

How exactly can we create a variable of a numeric type? Let's take a look at the example.

python
Input:
# Creating an integer
a = 5
print(f'This is an integer = {a}')

# Creating a floating point number
b = 10.6
print(f'This is a floating point number = {b}')

# Creating a complex number
c = 43 + 6j
print(f'This is a complex number = {c}')

Output:
This is an integer = 5
This is a floating point number = 10.6
This is a complex number = (43+6j)

As we can see from the examples, creating a variable of a numeric type is very simple, be it an integer or a complex one, we just need to assign a value to the variable.

In the example, we can see an unusual moment for us, namely print(f'This is an integer = {a}').These are the so-called f-strings. f-strings allow us to print strings with variables in a single pair of quotes. Let's look at the syntax. All text we want to print must be enclosed in quotation marks preceded by an f, and any variables we want to print within that text must be enclosed in curly braces.

And now let's have a practice.

Aufgabe

Swipe to start coding

  • You need to create the following numeric types as integer, floating point number, complex number

  • Please, use the following numbers for it:

integer : 784

floating point number: 658.34

complex number: 65+7j

Lösung

# Creating an integer
# Write your code here
a =784
print(f'This is an integer = {a}')

# Creating a floating point number
# Write your code here
b = 658.34
print(f'This is a floating point number = {b}')

# Creating a complex number
# Write your code here
c = 65+7j
print(f'This is a complex number = {c}')

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 1
# Creating an integer
# Write your code here
a = _ _ _
print(f'This is an integer = {a}')

# Creating a floating point number
# Write your code here
b = _ _ _
print(f'This is a floating point number = {b}')

# Creating a complex number
# Write your code here
c = _ _ _
print(f'This is a complex number = {c}')

toggle bottom row
some-alt