Data Types
There are 8 data types, they are:
Data Types
Whole Numbers, positive or negative
Example:
- 2 444 66
Data Types
Decimal numbers eg. 2.3 33.0 0.009
Apart from using decimal point they also sometimes use Exponential (E)
\ (e) to define the number.
For example: 4E2 (4 times 10 to the power of 2)
Data Types
Ordered sequence of Characters- ‘‘hello’’ ‘999’ “34ndj”
Data Types
Ordered sequence of Objects - [“apple”, 10, 1.24]
Data Types
Unordered Key, value pairs - {“mykey”: “value”, “name”: “franky”}
Data Types
Ordered immutable sequence of objects -
( 10, “hello”, 200.3)
Data Types
Unordered collection of unique objects - {“a”, “b”}
Data Types
Logical Value indicating - True or False
Data Types
Data type is a classification that specifies which type of value a variable has.
Data type
i. A python variable is a symbolic name that is a reference or pointer to an object.
ii. Once an object is assigned to a variable, one can refer to the object by that name.
iii. But the data itself is still contained within the object. For example
n = 300
Data type
Numbers
Addition +
Subtraction. -
Multiplication *
Division /
Floor Division. //
( eg. 7 // 4 = 1 . The // operator (two forward slashes) truncates the decimal without rounding, and returns an integer result)
.Power **
Mod %
Data type
Modulo or Mod operator
Data type
Modulo or Mod
Data type
Integer - Whole Number
Floating point - Decimal Number
Variable Assignments
Variable Assignments
i. Names can’t start with number
ii. No spaces in the name, _ can be used instead
iii. Can’t use symbols like - : “” ‘’ , <> | \ ? / () ! @ # $ % ^ & * ~ - +
iv. Use lowercase (according to PEP8)
v. Avoid Special Meaning words like “list”, “str”, ect.,
vi. Avoid using ( L ) , ( O ) , ( I ) because they can mistook as 1 and 0
Data type
Dynamic
Data type
Dynamic typing enables to reassign variables to different data types.
String
Assigning and Reassigning
i. For the variable assignment ___ assignment operator is used. an example ___
ii. What command should be applied, to find a Type of a variable?
i. = , name = object
ii. type( variable name )
String
Strings - Ordered Sequences of Characters, which means Indexing and Slicing can be done to grab sub-sections of the string
- Using Syntax of ‘ ‘or “ “
- Example: ‘hello’, “hello”, “I don’t do that”
String
Character : H E L L O
Index : 0 1 2 3 4
Reverse Index : 0 -4 -3 -2 -1
String
Slicing - Grabs a subsection of multiple characters
i.e. A “Slice of a string”
Start - Numerical index for the slice Start
Stop - The index u will go uptown but not include
Step - Size of the ‘Jump’ u take
String
The commons has taken out the double quotes and given the output
print (“Hello World”)
Hello World