8000 Data Types · dsabhrawal/python-examples@1e244b8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e244b8

Browse files
committed
Data Types
1 parent a8d8565 commit 1e244b8

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed

DataTypes/Boolean.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
x = 10
2+
y = 20
3+
z = x > y
4+
5+
print(type(x))
6+
print(type(y))
7+
print(type(z))
8+
print(z)

DataTypes/None.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
x = 10
2+
3+
print(type(x))
4+
5+
x = None
6+
7+
print(type(x))
8+
9+
10+
#All variables points to single locaiton of None value in Memory
11+
x = None
12+
y = None
13+
z = None
14+
15+
print(id(x))
16+
print(id(y))
17+
print(id(z))
18+
19+
#Answer
20+
#139932057840128
21+
#139932057840128
22+
#139932057840128

DataTypes/Numbers.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
w = 9 #Default Number representation base 10 decimal
3+
x = 0b1010 #Binary number base 2
4+
y = 0o1247 #Octal Number base 8
5+
z = 0xa43d #Hexadecimal number base 16
6+
7+
print(w);
8+
print(type(w));
9+
10+
print(x);
11+
print(type(x));
12+
13+
print(y);
14+
print(type(y));
15+
16+
17+
print(z);
18+
print(type(z));
19+
20+
#decimal to hex conversion
21+
print(hex(w));
22+
#decimal to octal
23+
print(oct(w));
24+
print(bin(w));
25+
26+
#Floating point number
27+
a = 10.25
28+
print(a)
29+
print(type(a))
30+
31+
#Floating point is upto 16 digit precision
32+
33+
#Complex Numbers
34+
p = 2 + 3j
35+
print(p.real) #print real value
36+
print(p.imag) #print imaginary value

DataTypes/String.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
s = "Hello Python" #Singline string
3+
print(s)
4+
print(type(s))
5+
6+
7+
#Multiple line strings
8+
#Mainly used for comments
9+
10+
s = '''This is a
11+
Multiple line
12+
string'''
13+
print(s)
14+
15+
s = '''It is 'a good' "example" '''
16+
17+
print(s)
18+
19+
#Next line
20+
print('\n \n')
21+
22+
#String Format for left/right/center justified
23+
s = 'Hello Python'
24+
#Left Justified
25+
s1 = format(s,'-<20')
26+
print(s1)
27+
28+
# Right Justified
29+
s1 = format(s,'->20')
30+
print(s1)
31+
32+
#center Justified
33+
s1 = format(s, '-^20')
34+
print(s1)
35+
36+
#String Functions
37+
print('\n\n')
38+
39+
s = 'Hellopython'
40+
print(len(s))
41+
print(max(s)) #based on ascci value
42+
print(min(s)) #based on ascii value
43+
44+
#String indexing
45+
print(s[1]) #first character
46+
print(s[-1]) #last character
47+
48+
#String slicing
49+
print(s[0:4])
50+
print(s[::2]) #every second character select
51+
52+
#String functions
53+
print(s.index('h'))
54+
print('\n')
55+
print(s.count('h'))
56+

0 commit comments

Comments
 (0)
0