Python - Data Types Flashcards
Review Major Concepts of Data Type in the Python Programming Language
Research: what is a Data Type in the Python Programming Language.
Data values in Python are known as objects; each object, aka value, has a type.
List and Describe: each Data Type in the Python Programming Language.
Numbers
Sequences
Sets
Dictionaries
None
Ellipsis (…)
Callables
Boolean Values
What is the ‘numbers’ data types in the Python Programming Language?
The ‘numbers’ data types are built-in numeric types such as integers, floating-point numbers and complex numbers.
What is a ‘sequence’ data type in the Python Programming Language?
A sequence is a container of ordered of items, indexed by integers.
What is a ‘set’ data type in the Python Programming Language?
A ‘set’ is a container of an arbitrarily ordered collection of unique items that can be of different types.
What is a ‘dictionary’ data type in the Python Programming Language?
A ‘dictionary’ is a container of mappings of an arbitrary collection of objects indexed by arbitrary values. An array of key-value pairs.
What is the ‘none’ data type in the Python Programming Language?
The ‘none’ data type denotes a null object.
Describe ‘callable’ data types in the Python Programming Language?
A ‘callable’ data type supports the function call operation. Examples are function, generators and methods.
What is the ‘boolean’ data type in the Python Programming Language?
A ‘boolean’ data type evaluates to either True of False. Any data value in python can be used as a truth value.
What are the three built-in types that are numerical data types?
The built-in numeric types in Python include integers, floating-point numbers, and complex numbers.
List and Describe: the four Integers literals of the numerical data types.
Decimal
A decimal literal is a sequence of digits in which the first digit is nonzero.
Binary
A binary literal is 0b followed by a sequence of binary digits (0 or 1).
Octal
An octal literal is 0o followed by a sequence of octal digits (0 to 7).
Hexadecimal
hexadecimal literal is 0x followed by a sequence of hexadecimal digits (0 to 9 and A to F, in either upper- or lowercase).
Describe: floating-point literals of the numerical data types.
A floating-point literal is a sequence of decimal digits that includes a decimal point (.), an exponent suffix (e or E, optionally followed by + or -, followed by one or more digits), or both.
Describe: Complex Number of the numerical data types.
A complex number is made up of two floating-point values, one each for the real and imaginary parts.
You can access the parts of a complex object z as read-only attributes z.real and z.imag.
Examples: 0j, 0.j, 0.0j, .0j, 1j, 1.j, 1.0j, 1e0j, 1.e0j, 1.0e0j
You can specify an imaginary literal as any floating-point or integer decimal literal followed by a j or J. The j at the end of the literal indicates the square root of -1, as commonly used in electrical engineering (some other disciplines use i for this purpose, but Python uses j).
Name three types of sequences in the Python Programming Language
Python has built-in sequence types known as strings (bytes or str), tuples, and lists.
Research: the term ‘iterate’, ‘iterable’ and ‘iterator’.
An iterable is any Python object capable of returning its members one at a time, permitting it to be iterated over in a for-loop.
What is the difference between a bounded iterable and an unbounded iterable in the Python Programming Language?
A bounded iterable is an iterable that eventually stops yielding items.
An unbounded iterable is an iterable that has no limit.
What are ‘strings’ in the Python Programming Language?
‘Strings’ are classified a ‘Sequences’.
‘Strings’ are objects that contain either a sequence of characters or a sequence of bytes.
Research the term ‘immutable’.
Wikipedia: an immutable object (unchangeable object) is an object whose state cannot be modified after it is created. This is in contrast to a mutable object (changeable object), which can be modified after it is created.
Are strings ‘mutable’ or ‘immutable’?
Strings of both types in Python are immutable: when you perform an operation on strings, you always produce a new string object of the same type, rather than mutating an existing string.
What is the difference between a single quoted string, a double quoted string and a triple quoted string.
All quoted strings create string literals, but in a triple quoted string, line breaks act as newline characters.
What are ‘raw string literals’ in the Python Programming Language?
‘Raw string literals’ do not evaluate escape sequences. They are quoted and triple quoted strings preceded with an ‘r’ or ‘R’.
What are ‘formatted string literals’?
Formatted string literals (commonly called f-strings) let you inject formatted expressions into your string “literals
How do you concatenate multiple string literals into one?
Use parentheses:
marypop = (‘supercali’ # ‘(‘ begins logical line,
‘fragilistic’ # indentation is ignored
‘expialidocious’) # until closing ‘)’
What is a ‘bytes’ object?
A bytes object is an immutable ordered sequence of ints from 0 to 255.