Python Data Types Tutorials and Interview Questions and Answers

Python :: Data Types

In this section we will cover Basic Introduction on Python Data Types in Python. This will helps to build basic block when constructing larger pieces of Python code. Let's discuss all of the possible data types available in Python.

Integers (int)
Whole numbers such as: 3 300 or 200

Floating Point (float)
Numbers with decimal point: 2.3 5.6 or 10.0

Strings (str)
Ordered sequence of characters: "hello" "world" '4000' "こんにちは"

Lists (list)
Orderred Sequence of objects: [10,"hello","world"]

Dictionaries (dict)
Unordered Key:Value pairs: {"name" : "Sam","company":"Eduzip"}

Tuples (tup)
Ordered immutable sequence of objects: (10,"hello",300.4)

Sets (set)
Unordered collection of unique objects: {"a","b"}

Booleans (bool)
Logical value indicating True or False

1. The following Python code

>>> [1, 2, 'stock', 4]

[A] Set
[B] List
[C] An error as there cannot be different data types in such a data structure
[D] Dictionary

The following Python code is a

>>> colors = ('red', 'yellow', 'blue', 'black')
[A] Set
[B] Dictionary
[C] List
[D] Tuple

The following Python code

>>> {'stock': 'NVO', 'wikipedia': 'Novo_Nordisk'}

is a

[A] Set
[B] Array
[C] Named array
[D] Dictionary

The following Python code

>>> a = range(5)
>>> b = a
>>> a[3] = 77

results in

[A] b = [0, 1, 2, 3, 4]
[B] b = [1, 2, 3, 4, 5]
[C] b = [0, 1, 2, 3, 4, 5]
[D] b = [0, 1, 2, 77, 4]

The following Python code

>>> 'Result: ' + 23

results in

[A] A string where the arguments are concatenated: 'Result: 23'
[B] 31
[C] An error as you cannot append an integer on a string
[D] A list: ['Results: ', 23]
6. Suppose a list with name test, contains 10 elements. You can get the 5th element from the test list using:
[A] test[5]
[B] test[4]
[C] test['5']
[D] test['4']

What is the output of the following program?

language = ['P', 'y', 't', 'h', 'o', 'n']

[A] 'Py'
[B] ['P', 'y']
[C] ['P', 'y', 't', 'h', 'o']
[D] [-4]
Are these questions helpful for you?

Comments: (Your feedback is valuable to us)