Class 2
Class 2
Conversion:
X = 25 -> binary print(bin(25)) o/p 0b11001
➔ Octal print(oct(25)) o/p 0o31
➔ Hexa decimal print(hex(25)) o/p 0x19
2. Float data type
• Number with decimal point
• i= 1.20
• float does not contain binary, octal, hexadecimal form
• exponential form:
to mention 1.2000000000000 we can mention 1.2e10
3. Complex data type:
• a+bj a--- real part, b--- imaginary part j value
• We can do *, / , + , - (mathematical operations)
• Real part (a) --- decimal, hexadecimal, octal, binary allowed
Imaginary part (b) --- decimal only allowed
4. Bool data type:
• True and False
• Value of True = 1
Value of False = 0
5. Str data type:
• Either single or double quotes
• s = ‘python is an easy language for programming’
s = “python”
s = ‘’’python ‘good’ lang’’’
s = “””python “good” lang”””
• Indexing:
s = ‘god is great’
forward 0 , 1, 2 …..
Type casting:
• int()
print(int(10.9)) --- o/p 10
print(int(10+20j)) --- o/p invalid
print(int(True)) --- o/p 1
print(int(‘123’)) --- o/p 123
• float()
print(float(10)) --- o/p 10.0
print(float(10+20j)) --- o/p invalid
print(float(True)) --- o/p 1.0
print(float(‘123’)) --- o/p 123.0
• complex()
print(complex(10)) --- o/p 10+0j
print(complex(10.5)) --- o/p 10.5+0j
print(complex(True)) --- o/p 1+0j
print(complex(False)) --- o/p 0+0j
print(complex(‘10’)) --- o/p 10+0j
print(complex(’10.5’)) --- o/p 10.5+0j
print(complex(‘ten’)) --- o/p invalid
• bool()
print(bool(0)) --- o/p False
print(bool(12)) --- o/p True
print(bool(0.0)) --- o/p False
print(bool(0.0001)) --- o/p True
print(bool(0+0j)) --- o/p False
print(bool(0+0.1j)) --- o/p True
print(bool(‘’)) --- o/p False
print(bool(‘False’)) --- o/p True
print(bool(‘yes’)) --- o/p True
print(bool(‘hgfu’)) --- o/p True
• str()
print(str(10)) ---- o/p ‘10’
print(str(10.5)) ---- o/p ’10.5’
print(str(10+20j)) ---- o/p ‘(10+20j)’
print(str(True)) ---- o/p ‘True’
print(str(0b1111)) ---- o/p ‘15’
Note:
int and float cannot be converted from complex
print(float(10+20j)) --- o/p invalid
print(int(10+20j)) --- o/p invalid