In [1]:
print('hello')
hello
In [3]:
a=10
In [6]:
print a
print('hi')
10
hi
In [23]:
_Age=10
print(_Age)
10
In [ ]:
age=1
Age
_age
__age

def class Age():
    def init:
        
__
In [ ]:
markrs = 65
if marks > 60 ( 
                
    
print('first division') print('first division')


            print('first division'))
In [62]:
marks = 65
if marks > 60:
    print('first division');print('first division');print('first division')
    
first division
first division
first division
In [41]:
str1 = 'abc\\' + \
    'xyz'
print(str1)
abc\xyz
In [36]:
str1 = {'abc' +
    'xyz'}
print(str1)
set(['abcxyz'])
In [37]:
days = ['Monday', 'Tuesday', 
        'Wednesday','Thursday', 'Friday']
In [ ]:
str1 = 'abc'
In [42]:
str
print(str)
str = "hello"
print(str)
str2 = """helooo"""
hi
hello
In [43]:
print(str)
hello
In [51]:
str7
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-51-f10ddb9ab3ec> in <module>()
----> 1 str7

NameError: name 'str7' is not defined
In [47]:
str8 = []
In [55]:
str2 = "select * from table1 \
where dept = 'IT' \
order by id \
"
print(str2)
select * from table1 where dept = 'IT' order by id 
In [57]:
str2 = """select * from table1
where dept = 'IT'
order by id
"""
# print(str2)
# hello
In [59]:
print('enter name')
a = raw_input()
enter name
hi
In [61]:
a=1;b=5;c=a*b
print(c)
5
In [68]:
str = 'hello world'

print(str[:7])
hello w
In [69]:
print(str*3)
hello worldhello worldhello world
In [72]:
print(str.upper())
HELLO WORLD
In [73]:
lst = [1,2,3,9]
lst
Out[73]:
[1, 2, 3, 9]
In [74]:
print(lst)
[1, 2, 3, 9]
In [76]:
lst2 = ['a','b','c',1,2]
lst2
Out[76]:
['a', 'b', 'c', 1, 2]
In [80]:
lst2[3:]
Out[80]:
[1, 2]
In [82]:
for i in lst2:
    print(i)
a
b
c
1
2
In [83]:
print(len(lst2))
5
In [87]:
for i in range(len(lst2)):
#     print(i)
    print(lst2[i])
a
b
c
1
2

dictionary

Python's dictionaries are kind of hash table type. They work like associative arrays or hashes found in Perl

and consist of key-value pairs.

In [11]:
dict1 = {'name':'ram','emp_id':1001,'dept':'IT'}
dict1
Out[11]:
{'dept': 'IT', 'emp_id': 1001, 'name': 'ram'}
In [15]:
print(dict1['dept'])
print(dict1['name'])
IT
ram
In [18]:
dict1.keys()
Out[18]:
['emp_id', 'dept', 'name']
In [19]:
dict1.values()
Out[19]:
[1001, 'IT', 'ram']
In [20]:
dict1 = {'row1':[1,2,3],
         'row2':[4,2,3],
         'row3':[7,2,3],
         'row4':[9,2,3],
         'row5':[6,2,3],
        }
dict1
Out[20]:
{'row1': [1, 2, 3],
 'row2': [4, 2, 3],
 'row3': [7, 2, 3],
 'row4': [9, 2, 3],
 'row5': [6, 2, 3]}
In [24]:
(dict1['row3'])[2]
Out[24]:
3
In [26]:
list(dict1.values())
Out[26]:
[[1, 2, 3], [4, 2, 3], [7, 2, 3], [9, 2, 3], [6, 2, 3]]
In [27]:
dict1.items()
Out[27]:
[('row1', [1, 2, 3]),
 ('row2', [4, 2, 3]),
 ('row3', [7, 2, 3]),
 ('row4', [9, 2, 3]),
 ('row5', [6, 2, 3])]
In [29]:
list(dict1.items())
Out[29]:
[('row1', [1, 2, 3]),
 ('row2', [4, 2, 3]),
 ('row3', [7, 2, 3]),
 ('row4', [9, 2, 3]),
 ('row5', [6, 2, 3])]
In [35]:
# (((dict1.items())[3])[1])[0]
(((dict1.items())[3])[1])[0]
Out[35]:
9
In [22]:
list1 = [[1,2,3],
         [1,2,3],
         [1,2,3]
        ]
list1
Out[22]:
[[1, 2, 3], [1, 2, 3], [1, 2, 3]]
In [ ]:
 
In [38]:
l1 = [10,20,30]
for i in l1:
    if i == 10:
        print("its "+str(i))
    elif i == 20:
        print('20')
    else:
        print(i)
its 10
20
30
In [41]:
a='hello'
print('this is %s'%a)
this is hello
In [ ]:
 
In [ ]:
 
In [ ]:
 
www.000webhost.com