Data Handling
Data Handling
Sub-types
Integers
Content→Whole numbers that have no fractional part
Sub-types
Integers (signed)
Content→Integers that can be both positive and negative
Length restriction→None
Sub-types
Big
Small
Booleans
Content→Truth values True and False
Floating-point numbers
Content→Numbers having fractional parts
Forms (Notations)
Fractional form→Normal decimal notation
Exponent form→a.bEe (a.b * 10e)
OverflowError↔Error raised if a given number cannot be represented
through the available number of bytes #PythonError
Advantages over integers
They can represent values between the integers.
They can represent a much greater range of values.
Disadvantages over integers
Floating-point operations are usually slower than integer
operations.
Precision→Double precision (15 digits)
Complex numbers
Forms (Notation)→A + Bj
Serialisation→Python prints the complex number in parenthesis if it
has a nonzero real part.
Difference in memory allocation→Complex literals and complex
variables may have different IDs even if they are equal
Components
Real component (floating point)
Imaginary component (floating point)
Sequences
Strings
Content→Any number of valid Unicode characters in a set of quotation
marks
Mutability→Immutable
Variable Internals
Object↔An entity that has certain properties and that exhibits a certain type
of behaviour
Attributes→Type, value, id
Type→Determines the operations that can performed on the object
Displayed using→type()
Value→The data-item contained in the object
Displayed using→print()
ID→The memory location of the object
Displayed using→id()
Operators
Types of operators
Identity
Bitwise
Membership
Arithmetic
Relational
Logical
Arithmetic Operators
Types
Unary→Operators that act on one operand
List→Unary +, Unary -
Binary→Operators that act on two operands
List
Addition
Subtraction
Multiplication
Division
Floor division
Modulus
Exponentiation
Augmented Assignment→Combinations of arithmetic and assignment
operators
Relational Operators↔Determine the relation among different operands
List←Less than (<), greater than (>), equal to (==), less than or equal to
(<=), greater than or equal to (>=), not equal to (!=)
How numeric types are compared→Trailing zeroes are moved, then the numbers
are compared
How strings are compared→Based on lexicographical ordering (ordering in a
dictionary)
How lists and tuples are compared→They are equal if they have the same
elements in the same order, otherwise they are compared element by element
How booleans are compared→True is 1, False is 0
Why floating point values should not be compared with ==→They are stored
with a precision limit which may result in rounding off.
Identity Operators↔Check if both operands reference the same object memory
List→is, is not
Cases in which Python creates different objects for two variables with the
same value
Input strings from the console beyond single characters
Integer literals from -6 and below and 257 and above (big integers)
Floating point and complex literals