Topic Covered
Topic Covered
Topic Covered:
Data Type: - Integer, Float, String, Complex Number, Boolean
Comments in Python and Input &Output Functions.
Data Types:
1. Integer:
They are positive or negative whole numbers with no decimal
point.
Range: Unlimited Range, we can any integer whether small or
long.
Function: int( )
Example: a = 15
2. Float:
They represent real numbers and are written with a decimal point
dividing the integer and fractional parts.
Floats may also be in scientific notation, with E or e indicating the
power of 10 (2.5e2 = 2.5 x 102 = 250).
Range: Maximum = 1.8e+308
Minimum = 1.0e-324
Function: float( )
Example: a = 15.16
3. String:
Python string is a collection of Unicode characters.
Python strings can be enclosed in single, double or triple quotes.
Eg: 'BlindSpot', "BlindSpot", ' ' 'BlindSpot' ' ', """Blindspot"""
String elements can be accessed using an index value, starting
with 0.
Eg:
msg = 'Hello'
0 1 2 3 4
‘H’ ‘e’ ‘l’ ‘l’ ‘0’
-5 -4 -3 -2 -1
a = msg[ 0 ] # yields H
b = msg[ 4 ] # yields o
d = msg[ -1 ] # yields o
e = msg[ -2 ] # yields l
f = msg[ -5 ] # yields H
Slicing of String: s[start : end+1 : step]
A sub-string can be sliced out of a string.
s[ start : end + 1 ] - extract from start to end
s[ start : ] - extract from start to end
s [ : end + 1] - extract from start to end
To Convert negative index to positive index:
Negative index + Length of String = Positive index
Examples of Valid String Literals:
“abcd”, “1234”, “%$#%”, “???#”, “Ram1234”
To find length of string we use len( ) function:
a = “Hello”
then, len(a) = 5