In [1]:
4
Out[1]:
4
In [4]:
import os
os.system('"sudo make_sandwich"')
Out[4]:
32512
In [6]:
a = 2
print(a*83)
166
In [2]:
print "helllo"
helllo
In [1]:
i = 4
In [2]:
print i
4
In [3]:
# int i = 4;
i = 4
In [4]:
f = 15.5
s = 'Hello'
In [5]:
print f
15.5
In [6]:
print s
Hello
In [7]:
s.capitalize()
Out[7]:
'Hello'
In [8]:
# List<String> names = new ArrayList<String>();
names = []
In [9]:
names
Out[9]:
[]
In [10]:
dict = {}
In [11]:
# Map<String, String> dict = new Hashmap<String, String>();
dict = {"person1":{"name": "Anas"}}
In [12]:
print dict
{'person1': {'name': 'Anas'}}
In [13]:
dict = {'a':4, 'b':7}
In [14]:
dict['a']
Out[14]:
4
In [15]:
names = ['Edward', 'Kim', 'mysterious man']
In [16]:
names[1]
Out[16]:
'Kim'
In [17]:
names[1:2]
Out[17]:
['Kim']
In [18]:
names[-1:]
Out[18]:
['mysterious man']
In [19]:
names
Out[19]:
['Edward', 'Kim', 'mysterious man']
In [20]:
sorted(l)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-20-5ed0ddfda5a6> in <module>()
----> 1 sorted(l)

NameError: name 'l' is not defined
In [21]:
sorted(names)
Out[21]:
['Edward', 'Kim', 'mysterious man']
In [22]:
reversed(names)
Out[22]:
<listreverseiterator at 0x9a56c8c>
In [23]:
names.pop(0)
Out[23]:
'Edward'
In [24]:
def myFunction(string):
    print string
In [25]:
myFunction("Natasha")
Natasha
In [32]:
# if (this is true) {

#} else {

#}


if (1 == 2):
    print "True"
elif(2==3):
    print "False"
else:
    print "You idiot"
You idiot
In [28]:
if (1==1): print "True" elif (2==3): print "False" else: print "Nothing makes sense anymore"
  File "<ipython-input-28-6084857058a4>", line 1
    if (1==1): print "True" elif (2==3): print "False" else: print "Nothing makes sense anymore"
                               ^
SyntaxError: invalid syntax
In [29]:
print "true" if 1 == 1
  File "<ipython-input-29-3917614132b8>", line 1
    print "true" if 1 == 1
                          ^
SyntaxError: invalid syntax
In [30]:
print "True" if (1==1)
  File "<ipython-input-30-777332cfd204>", line 1
    print "True" if (1==1)
                          ^
SyntaxError: invalid syntax
In [33]:
#for(int i = 0; i< 10; ++i)
for i in range(0,10):
    print i
0
1
2
3
4
5
6
7
8
9
In [1]:
class Person(object):
    def __init__(self, name, age):
        self.name = name
        self.age = age
    def grow(self, years):
        self.age += years
In [4]:
me = Person("Charles", 49)
In [3]:
me = new Person
  File "<ipython-input-3-d755d4195e99>", line 1
    me = new Person
                  ^
SyntaxError: invalid syntax
In [6]:
me.age
Out[6]:
49
In [7]:
me.grow(10)
In [8]:
me.age
Out[8]:
59
In [9]:
# import java.util.Date
date?
Object `date` not found.
In [10]:
import date
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-10-c9fb87721c28> in <module>()
----> 1 import date

ImportError: No module named date
In [11]:
import os
In [12]:
import time
In [1]:
a = "This is"
b = " the best python tutorial ever"
a + b
Out[1]:
'This is the best python tutorial ever'
In [2]:
a = ''
for i in range(0,10):
    a += 'a'
print a
aaaaaaaaaa