Data Types Flashcards
What is a Data Type in Python?
Data Type represents the type of data present inside a variable.
Is Python a statically or dynamically typed language?
Python is a Dynamically Typed Language.
List the inbuilt data types in Python.
- int
- float
- complex
- bool
- str
- bytes
- bytearray
- range
- list
- tuple
- set
- frozenset
- dict
- None
What function is used to check the type of a variable in Python?
type()
What function is used to get the address of an object in Python?
id()
What is the int data type used for in Python?
The int data type is used to represent whole numbers (integral values).
How can int values be represented in Python?
- Decimal form
- Binary form
- Octal form
- Hexadecimal form
What prefix is used for binary literals in Python?
0b or 0B
What prefix is used for octal literals in Python?
0o or 0O
What prefix is used for hexadecimal literals in Python?
0x or 0X
What does the bin() function do in Python?
The bin() function converts from any base to binary.
What does the oct() function do in Python?
The oct() function converts from any base to octal.
What does the hex() function do in Python?
The hex() function converts from any base to hexadecimal.
What is the float data type used for in Python?
The float data type is used to represent floating point values (decimal values).
How can floating point values be represented in Python?
Floating point values can be represented by using exponential form (scientific notation).
What is a complex number in Python?
A complex number is of the form a + bj, where j^2 = -1.
What are the only allowed values for the bool data type in Python?
True and False.
What is the str type used for in Python?
The str type represents a sequence of characters enclosed within single or double quotes.
How can multi-line strings be represented in Python?
Multi-line strings can be represented using triple single quotes (‘’’) or triple double quotes (“””).
What is slicing in Python strings?
Slicing is retrieving parts of a string using the [ ] operator.
What is the index system for strings in Python?
Python Strings follow zero-based indexing.
What are the fundamental data types in Python?
- int
- float
- complex
- bool
- str
What is Type Casting in Python?
Type Casting is converting one type value to another type.
What function is used to convert values to int in Python?
int()