[go: up one dir, main page]

0% found this document useful (0 votes)
4 views3 pages

Class 2

Uploaded by

Deva Monish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Class 2

Uploaded by

Deva Monish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Fundamental Data types:

1. int data type


• Decimal form : x = 16548465483680 (allowed digits 0 to 9)
• Binary form : x = 0b1011 (allowed digits 0 and 1)
• Octal form : x = 0o7023 (allowed digits 0 to 7)
• Hexa decimal : x = 0X09Face (0 to 9, A to F, a to f)

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’

print(s[-1]) ---- ‘g’

print(s[0]) ---- ‘g’

forward 0 , 1, 2 …..

backward -1, -2, -3….


• Slicing:
s = ‘god is great’
uses : to access
print(s[0:2]) --- o/p ‘god’
print(s[:4]) --- o/p ‘god i’
print(s[6:]) --- o/p ‘ great’
print(s[:]) --- o/p ‘god is great’

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

You might also like