In [37]:
print "(SHIFT + ENTER) will run a cell."
In [38]:
mList = [1,2,3]
In [39]:
print "TAB will show a popup of the methods on an object!!"
In [40]:
print "(SHIFT + TAB) will show help popup for docstring."
In [41]:
# help(mList)
In [42]:
# This is a comment
In [ ]:
In [43]:
2+1
Out[43]:
In [44]:
2+2
Out[44]:
In [45]:
3-1
Out[45]:
In [46]:
2*5
Out[46]:
In [47]:
1/5
Out[47]:
In [48]:
3/2 # classic integer division
Out[48]:
In [49]:
3.0/2 # true division
Out[49]:
In [50]:
3/2.0
Out[50]:
In [51]:
float(3) #casting:
Out[51]:
In [52]:
#importing capabilities from python3 into python2
from __future__ import division
In [53]:
3/2 #(due to __future__)
Out[53]:
In [54]:
# power
12**2
Out[54]:
In [55]:
# square root
144**0.5
Out[55]:
In [56]:
a = 5
In [57]:
a
Out[57]:
In [58]:
a+a
Out[58]:
In [59]:
a = 10
In [60]:
a
Out[60]:
In [61]:
a = a+a
In [62]:
a
Out[62]:
In [63]:
my_income = 1000000
In [64]:
tax_rate = 0.2
In [65]:
my_taxes = my_income * tax_rate
In [66]:
my_taxes
Out[66]:
In [ ]:
In [67]:
'Hello'
Out[67]:
In [68]:
'This is also a string'
Out[68]:
In [69]:
'I'm a string # ERROR
In [70]:
"I'm a string" #OK
Out[70]:
In [71]:
'Hello World 1'
'Hello World 2'
Out[71]:
In [72]:
# print statement
print 'Hello World 1'
print 'Hwllo World 2'
In [73]:
print 'Here is a new line \n and here is a 2nd line'
In [74]:
print 'before TAB \t after TAB'
In [75]:
print("hello World")
In [76]:
# To use print function from Python3 in Python2
from __future__ import print_function
In [77]:
print ('how are you')
In [78]:
len('Hello World')
Out[78]:
In [79]:
s = 'Hello World'
In [80]:
s
Out[80]:
In [81]:
# indexing
s[0]
Out[81]:
In [82]:
s[5]
Out[82]:
In [83]:
# slicing
s[1:]
Out[83]:
In [84]:
s[1:7]
Out[84]:
In [85]:
s[:8]
Out[85]:
In [86]:
s[:]
Out[86]:
In [87]:
s[1:1]
Out[87]:
In [88]:
s[-1]
Out[88]:
In [89]:
s[-2]
Out[89]:
In [90]:
s[:-1]
Out[90]:
In [91]:
s[:-2]
Out[91]:
In [92]:
s[::1]
Out[92]:
In [93]:
s[1:5:1]
Out[93]:
In [94]:
s[1:5:2]
Out[94]:
In [95]:
s[::2]
Out[95]:
In [96]:
s[::-1] # reversing the string backwards
Out[96]:
In [97]:
# immutability
s[2] = 'P' # cannot assign to a particlar element in a string sequence
In [98]:
# concatenation
s + "Concatenate me!"
Out[98]:
In [99]:
# multiplication
letter = 'p'
In [100]:
letter
Out[100]:
In [101]:
letter * 10
Out[101]:
In [116]:
print letter * 18
In [112]:
print(letter * 5)
In [113]:
s = 'rustom'
In [114]:
# uppercase
s.upper()
Out[114]:
In [115]:
# lowercase
s.lower()
Out[115]:
In [117]:
# splitting a string
s.split('o') # splitting around 'o'
Out[117]:
In [ ]:
In [1]:
print 'This is a string'
In [2]:
print('This is a string')
In [3]:
m_str = 'String'
print 'Place my variable here: %s' %(m_str)
In [4]:
x = 13.35
print 'Place my variables here: %s' %(x)
In [5]:
print 'Floating point number: %1.2f' %(82.175)
In [6]:
print 'Floating point number: %1.12f' %(82.175)
In [7]:
print 'Floating point number: %18.2f' %(82.175)
In [8]:
#conversion methods:
print 'Conversion to string %r' %(15.96)
In [9]:
print 'first: %s, \nsecond: %s, \nthird: %s' %('hi', 'rus', 'potter')
In [10]:
print 'First: {x} \nSecond: {x}'.format(x = "Hello Potter")
In [11]:
print 'First: {x}, \nSecond: {y}, \nThird: {z}'.format(x = "Hariom", y = "Guruji", z = 'OmGuru')
In [12]:
from __future__ import print_function
In [13]:
print('hello')
In [14]:
print('First: {x}'.format(x = 'INSERT!!!'))
In [ ]: