Data Types Flashcards

1
Q

What is a Data Type in Python?

A

Data Type represents the type of data present inside a variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Is Python a statically or dynamically typed language?

A

Python is a Dynamically Typed Language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

List the inbuilt data types in Python.

A
  • int
  • float
  • complex
  • bool
  • str
  • bytes
  • bytearray
  • range
  • list
  • tuple
  • set
  • frozenset
  • dict
  • None
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What function is used to check the type of a variable in Python?

A

type()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What function is used to get the address of an object in Python?

A

id()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the int data type used for in Python?

A

The int data type is used to represent whole numbers (integral values).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How can int values be represented in Python?

A
  • Decimal form
  • Binary form
  • Octal form
  • Hexadecimal form
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What prefix is used for binary literals in Python?

A

0b or 0B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What prefix is used for octal literals in Python?

A

0o or 0O

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What prefix is used for hexadecimal literals in Python?

A

0x or 0X

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the bin() function do in Python?

A

The bin() function converts from any base to binary.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does the oct() function do in Python?

A

The oct() function converts from any base to octal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the hex() function do in Python?

A

The hex() function converts from any base to hexadecimal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the float data type used for in Python?

A

The float data type is used to represent floating point values (decimal values).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How can floating point values be represented in Python?

A

Floating point values can be represented by using exponential form (scientific notation).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a complex number in Python?

A

A complex number is of the form a + bj, where j^2 = -1.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are the only allowed values for the bool data type in Python?

A

True and False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is the str type used for in Python?

A

The str type represents a sequence of characters enclosed within single or double quotes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How can multi-line strings be represented in Python?

A

Multi-line strings can be represented using triple single quotes (‘’’) or triple double quotes (“””).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is slicing in Python strings?

A

Slicing is retrieving parts of a string using the [ ] operator.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the index system for strings in Python?

A

Python Strings follow zero-based indexing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What are the fundamental data types in Python?

A
  • int
  • float
  • complex
  • bool
  • str
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is Type Casting in Python?

A

Type Casting is converting one type value to another type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What function is used to convert values to int in Python?

A

int()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What function is used to convert values to float in Python?
float()
26
What function is used to convert values to complex in Python?
complex()
27
What function is used to convert values to bool in Python?
bool()
28
What function is used to convert values to str in Python?
str()
29
What does immutability mean in the context of Python's fundamental data types?
Immutability means that once an object is created, it cannot be changed.
30
What is the bytes data type in Python?
The bytes data type represents a group of byte numbers, similar to an array.
31
What is the value range for the bytes data type?
0 to 256 ## Footnote Providing values outside this range results in a ValueError.
32
What error occurs if we try to modify a bytes object?
TypeError ## Footnote Example: Trying to assign a new value to a specific index in a bytes object.
33
What is the main difference between bytes and bytearray?
bytearray is mutable, while bytes is immutable.
34
What does a list data type allow?
* Insertion order is preserved * Heterogeneous objects are allowed * Duplicates are allowed * Growable in nature
35
What is a tuple?
An immutable ordered collection of objects.
36
What error is raised when trying to modify a tuple?
TypeError ## Footnote Example: Attempting to assign a new value to a tuple element.
37
What does the range data type represent?
A sequence of numbers.
38
How do you create a range that generates numbers from 10 to 19?
range(10, 20)
39
What is a key characteristic of the set data type?
Duplicates are not allowed.
40
What is frozenset?
An immutable version of a set.
41
What does the dict data type represent?
A group of key-value pairs.
42
What happens when a duplicate key is added to a dictionary?
The old value will be replaced with the new value.
43
What is the None data type in Python?
Represents nothing or no value associated.
44
What is the purpose of escape characters in Python strings?
To associate special meanings within string literals.
45
What does the escape character '\n' represent?
New Line
46
What is the convention for defining constants in Python?
Use uppercase characters, e.g., MAX_VALUE=10.
47
What type of collection is a list?
An ordered, mutable, heterogeneous collection of elements.
48
What is the syntax to create a list in Python?
Values should be enclosed within square brackets.
49
What does the type function return for an integer variable?
50
Is the bytes data type mutable or immutable?
Immutable.
51
What are the allowed values for the bytearray data type?
Values from 0 to 255.
52
What is the characteristic of a mutable collection?
The size and content can change over time.
53
What is the primary difference between a list and a tuple?
A list is mutable, while a tuple is immutable.
54
What does the 'range(10, 20, 2)' function generate?
Numbers from 10 to 19 with an increment of 2.
55
What is the output of 'set([1,2,2,3])'?
{1, 2, 3}
56
What happens if you try to index a set?
TypeError ## Footnote Example: Attempting to access a set element using an index.
57
What is the output of 'frozenset({1, 2, 3})'?
frozenset({1, 2, 3})
58
What type of values does the boolean data type represent?
Logical values (True and False).
59
What is the output of 'type([])'?
60
What does 'b=bytearray([10,20,30])' create?
A mutable sequence of byte values.
61
What is the output of 'd={101:'durga', 102:'ravi'}'?
A dictionary with two key-value pairs.
62
True or False: The dict type preserves insertion order.
True.
63
What is the result of attempting to add a value to a frozenset?
AttributeError ## Footnote Frozensets do not support item assignment.
64
What is the syntax to create an empty dictionary?
{}
65
Fill in the blank: The _______ data type represents a sequence of byte values from 0-255.
bytes