Integers
So, integers are numbers that do not contain a fractional part. These numbers can be both positive and negative (for example 10, -7 both of these numbers are integers). Let's take a look at the example below.
python991234567891011Input:# Creating integersx = 7y = -10print(f'It's a positive integer: {x}')print(f'It's a negative integer: {y}')Output:It's a positive integer: 7It's a negative integer: -10
Sometimes you have to check the type of some variables. In python, for it there is an useful function called type(). Let's look at an example of how this function works.
python991234567891011Input:# Creating integersx = 7y = -10print(f'The type of x is {type(x)}')print(f'The type of y is {type(y)}')Output:The type of x is <class 'int'>The type of y is <class 'int'>
It's time to practice!
Compito
Swipe to start coding
Create three variables: a, b, c
with the following values: 100, -5, -12350
and check the types of them.
Soluzione
9
1
2
3
4
5
6
7
8
a = 100
b = -5
c = -12350
print(f'It`s a: {a}, the type of a is {type(a)}')
print(f'It`s b: {b}, the type of b is {type(b)}')
print(f'It`s c: {c}, the type of c is {type(c)}')
Tutto è chiaro?
Grazie per i tuoi commenti!
Sezione 1. Capitolo 2
single
9
1
2
3
4
5
6
7
8
# Creating variables
a = _ _ _
b = _ _ _
c = _ _ _
print(f'It`s a: {a}, the type of a is {_ _ _}')
print(f'It`s b: {b}, the type of b is {_ _ _}')
print(f'It`s c: {c}, the type of c is {_ _ _}')
Chieda ad AI
Chieda ad AI
Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione