In [2]:
%matplotlib inline

In [4]:
x=[]
x.append(1)
x


Out[4]:
[1]
$$ x $$

In [5]:
"""
Origin: A simple example.
Filename: example_scatter.py
Author: Tyler Abbot
Last modified: 15 September, 2015

qsdlmkfjdlmqksdfj
"""
import matplotlib.pyplot as plt
import random

x, y = [], []
for i in range(0,50):
   #This is a comment
   x.append(random.random())
   y.append(random.random())

plt.scatter(x, y)
plt.xlabel('x')
plt.ylabel('y')
plt.title('A Bivariate Uniform Random Variable')
plt.show()


/home/pi/env/lib/python3.4/site-packages/matplotlib/collections.py:590: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if self._edgecolors == str('face'):

In [16]:
x = [[1,1], [2,2]]
x[1]


Out[16]:
[2, 2]

In [19]:
words = ['hello', 'there', 'everyone', 1]
for word in words: 
    print(word)
    print(word +1)


hello
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-19-6d45aa056b22> in <module>()
      2 for word in words:
      3     print(word)
----> 4     print(word +1)

TypeError: Can't convert 'int' object to str implicitly

In [ ]:
x = 1
while True:
    print("To infinity and beyond! We're getting close,"\
           + " on %d now!" % (x))
    x += 1
    break

In [20]:
#Create a string
x = "You better fill this in at some point..."
print(x)


You better fill this in at some point...

In [30]:
y = list(range(0,10))
print(y)
print(x[:2])
#Slice a string
print(x[:-3])
print(x[:-4])


[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Yo
You better fill this in at some point
You better fill this in at some poin

In [28]:
#Change the case
print(x.lower())
print(x.upper())


you better fill this in at some point...
YOU BETTER FILL THIS IN AT SOME POINT...

In [32]:
#Find the index of a substring
print(x.find('fill'))
print(x[11:])


11
fill this in at some point...

In [ ]:
#Create a string
x = "You better fill this in at some point..."
print(x)

#Slice a string
print(x[:-3])

#Change the case
print(x.lower())
print(x.upper())

#Find the index of a substring
print(x.find('fill'))
print(x[11:])

In [33]:
#Define a tuple
tup = 1, 2, 3
tup1 = ("a", "b", "c")
print(tup)
print(tup1)


(1, 2, 3)
('a', 'b', 'c')

In [34]:
#Retrieving tuple data
print(tup[0])


1

In [36]:
#Define a tuple
tup = 1, 2, 3
tup1 = ("a", "b", "c")
print(tup)
print(tup1)

#Retrieving tuple data
print(tup[0])

#This won't work, since tuples are immutable
#tup[0] = 1
del tup
print(tup)


(1, 2, 3)
('a', 'b', 'c')
1
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-36-ffdd7fb3b87b> in <module>()
     11 #tup[0] = 1
     12 del tup
---> 13 print(tup)

NameError: name 'tup' is not defined

In [37]:
#Define a dictionary
packages = {'NumPy': 'arrays',
            'SciPy': 'numerical methods',
            'Pandas': 'statistics'}

#Get info
print(packages.items())
print(packages.get('matplotlib'))
print(packages['NumPy'])


dict_items([('SciPy', 'numerical methods'), ('NumPy', 'arrays'), ('Pandas', 'statistics')])
None
arrays

In [44]:
#Define a dictionary
packages = {'NumPy': 'arrays',
            'SciPy': 'numerical methods',
            'Pandas': 'statistics'}

#Get info
print(packages.items())
print(packages.get('matplotlib'))
print(packages['NumPy'])

#Loop through the dictionary
for package, use in packages.items():
    print("%s is most useful for %s." %(package, use))
    print(str(package) + " is a package")


dict_items([('SciPy', 'numerical methods'), ('NumPy', 'arrays'), ('Pandas', 'statistics')])
None
arrays
SciPy is most useful for numerical methods.
SciPy is a package
NumPy is most useful for arrays.
NumPy is a package
Pandas is most useful for statistics.
Pandas is a package

In [43]:
x = list(range(100,110))
x
for i, j in enumerate(x):
    print(i, j)
    
i=0
for j in x:
    print(i, j)
    i += 1


0 100
1 101
2 102
3 103
4 104
5 105
6 106
7 107
8 108
9 109
0 100
1 101
2 102
3 103
4 104
5 105
6 106
7 107
8 108
9 109

In [ ]: