In [2]:
%matplotlib inline
In [4]:
x=[]
x.append(1)
x
Out[4]:
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()
In [16]:
x = [[1,1], [2,2]]
x[1]
Out[16]:
In [19]:
words = ['hello', 'there', 'everyone', 1]
for word in words:
print(word)
print(word +1)
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)
In [27]:
y = list(range(0,10))
print(y)
print(x[:2])
#Slice a string
print(x[:-3])
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 [ ]:
#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
In [ ]:
#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))