Data Types¶

Boolean Data Type¶

In [ ]:
True
Out[ ]:
True
In [ ]:
False
Out[ ]:
False
In [ ]:
True and False
Out[ ]:
False
In [ ]:
True or False
Out[ ]:
True
In [ ]:
not False
Out[ ]:
True

Number Data Type¶

In [ ]:
4 + 5
Out[ ]:
9
In [ ]:
4 * 5
Out[ ]:
20
In [ ]:
4 - 5
Out[ ]:
-1
In [ ]:
5 / 2
Out[ ]:
2.5
In [ ]:
5 // 2
Out[ ]:
2
In [ ]:
5 % 2
Out[ ]:
1
In [ ]:
2253 // 100
Out[ ]:
22
In [ ]:
2253 % 100
Out[ ]:
53

String Data Type¶

In [ ]:
"hello"
Out[ ]:
'hello'
In [ ]:
'''hello'''
Out[ ]:
'hello'
In [ ]:
'''
select  fname
from   students
where  major = 'CSC'
'''
Out[ ]:
"\nselect  fname\nfrom   students\nwhere  major = 'CSC'\n"
In [ ]:
"hello" + " " + "how are you?"
Out[ ]:
'hello how are you?'
In [ ]:
len("hello")
Out[ ]:
5
In [ ]:
"123"
Out[ ]:
'123'
In [ ]:
int("123")
Out[ ]:
123
In [ ]:
int("123a")
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [23], in <cell line: 1>()
----> 1 int("123a")

ValueError: invalid literal for int() with base 10: '123a'
In [ ]:
try:
    int("123a")
except:
    print("conversion error")
    #sys.exit()
conversion error

STATEMENTS¶

assignment statement¶

In [ ]:
x = 5
print(x)
x = 6
print(x)
5
6
In [ ]:
print(5 > 7)
5 == 7
5 <= 7
5 < 7
5 >= 7
5 != 7
False
Out[ ]:
True
In [ ]:
hour = 2
if hour == 0:
    shour = "zero"
elif hour == 1:
    shour = "one"
elif hour == 2:
    shour = "two"
else:
    shour = "twenty three"
print(shour)
two
In [ ]:
# conditional statement
age = 17
if age > 12 and age < 20:
    print("Teenage")
else:
    print("not teenage")
Teenage