CH 3 - DATA HANDLING (Module 4) Flashcards
(30 cards)
python built in core data types
- numbers
- strin
- list
- tuple
- dictionary
numbers (types)
- integers
i. integers (signed)
ii. booleans - floating point numbers
- complex numbers
bool(0)
false
bool(1)
true
floatin point numbers advantages over inteers
- they can represent values between inteer
2 wider range of numbers it can represent
disadvantae of floatin point number
they are slower than inteer operations
python respresents complex numbers in what form
A + Bj
a = 0 + 3.1j
b = 1.5 + 2j
why is j symbol used to represent complex number i
z = 2.5 + 3.9j
print(z.real) and print(z.imag)
2.5 and 3.9
python index or subscript
the numbered position of a letter in the string
- a python string is a sequence of characters and each character can be accessed using its index
- strings in python are stored as INDIVIDUAL CHARACTERS in contiguous location with TWO WAY INDEX for EACH LOCATION
python indices length
python indices begin 0 onwards in forward direction and -1, -2 in backward direction
- the length of python index of any string from forward would be lenth-1 since index starts from 0
are strings immutable or mutable
IMMUTABLE
how are strings immutable
- you cannot change the individual letters of a string in place by assignment because STRINS ARE IMMUTABLE
- hence, ITEM ASSINMENT IS NOT SUPPORTED
for ex:
name = “hello”
name[0] = “p”
error aayega
lists [1, 2, 3]
lists in python represent a list of comma separated values of any datatype between square brackets
are lists immutable or mutable
mutable
a = [1, 2, 3] chane 1 to 10 in th elist
a [0] = 10
print(a)
a = [10, 2, 3]
tuples ( )
represented as a roup of comma separated values of any data type with paranthesis/ brackets
are lists immutable or mutable
immutable
sets
similar to lists that can store multiple values same as mathematical sets
differences bw sets and lists
sets lists
{ } [ ]
unordered and unindexed
doesnt allow duplicate entries
cannot contain mutable elements
SIMILARITY: BOTH ARE MUTABLE THO
what deos it mean that sets cannot CONTAIN mutable elements
a list cannot exist inside a set
ex: { 1, 2, [3, 4] } = 3,4 is a list which is written inside set
however, a tuple CAN BE CONTAINED inside a set since a tuple is immutable
ex: { 1, 2, (3, 4)
are sets immutable or mutable
MUTABLE
even thouh it cannot contain mutable elements, it is MUTABLE
dictionary
it is an unordered set of comma sepaqrated key: value pairs within { }
- no keys can be the same in a dictionary
- THERE ARE UNIQUE KEYS IWTHIN A DICTIONARY
everything is a ______ in python
object: it is an entity that has certain properties and that exhibit a certain type of behaviour
- python calls every entity that stores any values or any type of data as an object
- cuz python is an object oriented language
- strins, tuples, lists, dictionaries (all data types), inteers, numbers, variables are all objects