Python Number Types Tutorials with MCQ Questions and Answers

In this section we will cover Python Number Types tutorials along with MCQ Question and Answers. Number data types store numeric values like 4, 3, 6634 or 3.3434. They are immutable data types, means that changing the value of a number data type results in a newly allocated object. This Python Number type Quiz will helps you to crack Interviews.

  • In this tutorial we will discuss two main number types:
    • Integers whish are whole numbers.
    • Floating Point numbers which are numbers with a decimal.
  • We will also discuss how to create variable and assign them values.

Variable Assignment

Above, we just saw how to work with numbers data type but what do these numbers represent? It would be nice to assign these data types to a variable name to easily reference them later on in our code.

For Example
my_cats = 5

Rules for variable names

  • Names can not start with a number.
  • there can be no spaces in the name use _ instead.
  • Can't use any of these symbols :"',!@#$%^&*()~+-
  • It's considered best practice (PEP8) that names are lowercase
  • Avoid using words that have special meaning in Python like "int", "list" and "str"

Dynamic Typing

  • Python uses Dynamic Typing means you can reassign variable to different data types.
  • This makes Python very flexible in assigning data types, this is different than other languages that are "Statically-Typed" see example below:

my_cats = 2
my_cats = ["Sam", "Eduzip"]
This will work in Python but Error in other languages.

Pros of Dynamic Typing

  • Very easy to work with
  • Faster development time

Cons of Dynamic Typing

  • May result in bugs for unexpected data types!
  • You need to be aware of type()

 

Number Examples

1.

What is the output of the following program?


print((1, 2) + (3, 4))

[A] (4, 6)
[B] (1, 2, 3, 4)
[C] ((1, 2), (3, 4))
[D] Error!
Loading...
2. Which one of these is a floating point number?
[A] 4
[B] 3.5
[C] 567
[D] 105
Loading...
3.

What is the output of the following program?



4 + 5 * 9 + 4
[A] 117
[B] 63
[C] 53
[D] 107
Loading...
4. Which of these will output the result 36?
[A] 6**6
[B] 3 + 6
[C] 6*6
[D] 30+*6
Loading...
5. In Python 3, what is the output of 1/2 ?
[A] 1
[B] 0
[C] 0.5
[D] Error!
Loading...
Are these questions helpful for you?

Comments: (Your feedback is valuable to us)