x = 100
x
s = "Hello" + " World"
s
pi = 3.1415
type(pi)
i = 10
j = 20
isGreater = i > 20
isGreater
m = None # null value
print(m)
type(m)
hetrogeneous_array = ["Apple", 100, 6.023]
print('hetrogeneous_array =', hetrogeneous_array) # Use this for printing in Python
type(hetrogeneous_array)
hetrogeneous_array.append(40) ## Add new items to an array
print(hetrogeneous_array)
hetrogeneous_array.__dir__()
tpl = ('Ram', 40, 1000)
tpl
tpl.__dir__()
## Tuple has no append function - so cannot add new elements to this later
should import the library
from collections import namedtuple
empl_list = []
nt = namedtuple( 'Employee', ['name', 'age', 'salary']);
empl_list.append ( nt._make(tpl) ) ## tpl from the above cell
new_emp = ('Adam', 25, 2000)
empl_list.append ( nt._make(new_emp) )
print( empl_list )
rainbow = { 'violet', 'indigo', 'blue', 'green', 'yellow', 'orange' }
print(rainbow)
rainbow.add('red')
print(rainbow)
rainbow.add('something') # add something once
rainbow.add('something') # add something twice
rainbow.add('something') # add something thrice
print(rainbow)
rainbow.discard('something')
# Unfortunately there is no ordered set. You have to implement your own ordered set
periodic_table = {
"elements": [
{
"name": "Hydrogen",
"atomic_mass": 1.008,
"number": 1,
"phase": "Gas"
},
{
"name": "Helium",
"atomic_mass": 4.0026022,
"number": 2,
"phase": "Gas"
}
]
}
type(periodic_table)
print( periodic_table['elements'][1]['name'] ) # Access an element inside the dictionary tree
print( periodic_table['elements'][1]['number'] ) # Access an element inside the dictionary tree
# print( 'Elements map = ' + periodic_table['elements'] ) ## error without str because + cannot convert to string
# print( 'Elements map = ' + str(periodic_table['elements']) )
print('Please input a number from 1 to 5: ')
user_ip = input()
my_num = int(user_ip)
if my_num == 1:
print('You keyed in One')
if my_num == 2:
print('You keyed in Two')
if my_num == 3:
print('You keyed in Three')
if my_num == 4:
print('You keyed in Four')
if my_num == 5:
print('You keyed in Five')
print('Please select a fruit: ')
print(' 1 - Orange ')
print(' 2 - Apple ')
user_ip = input()
my_num = int(user_ip)
if my_num == 1:
print(' You probably like Oranges ')
elif my_num == 2:
print(' You probably like Apples ')
else:
print(' You probably don\'t know English')
print(rainbow)
print('=================================================================')
for color in rainbow:
print(color)
print('=================================================================')
for idx, color in enumerate(rainbow):
print(idx, ' - ', color)
i = 1
while i < 6:
print(i)
i += 1 ## Remember to do this incremental operation. Else the program will go to an infinite loop