year = 2018 # integer
float = 454.09 # floating point
message = "Hello World!" # string
year = 2018
age = 10
result = year + age
'''
+ : Addition - : Subtraction
* : Multiplication / : Division
% : Modulus Division **: Exponent
'''
result += 50 # Addition assignment operator
result -= 18 # Subtraction assignment operator
year = 2018
if year < 2018:
print "Before 2018"
elif year > 2018:
print "After 2018"
else:
print "The year is 2018!"
'''
== : Equal to != : Not Equal to
> : Greater than < : Less than
>= : Greater than or equal to <= : Less than or equal to
'''
num = 0
# While Loop
while (num < 10):
num += 1
# For Loop
# iterates from 0 (inclusive) to 100 (exclusive)
for i in range(0, 100):
num += 1
# See List section to easily iterate through list elements
grades = [97, 84, 89, 93]
print grades[0] # prints 97
grades[1] = 90 # changes grade 84 to 90
grades.append(95) # puts 95 at the end of the list (index 4)
grades.remove(90) # remoeve cases of 90 from the list
grades.insert(0, 99) # insert value 99 at the index 0
# print out every grade
for grade in grades: # iterates through every item in list
print grade # "grade" is the current element
# get a section of the list
foo = grades[1:3] # [first:last]
# returns sublist from index 1 (inclusive)
# to index 3 (exclusive) of grades list
bar = grades[2:] # returns sublist from index 2 (inclusive)
# to end of grades list
def maxValue(num1, num2):
if num1 > num2:
return num1
else:
return num2
print maxValue(5, 10) # prints 10
class Person:
name = "Default Name"
age = 0
def __init__(self, name, age):
self.name = name
self.age = age
def sayHello(self):
print "Hello!"
friend = Person("Austin", 21)
print friend.name # prints "Austin"
friend.sayHello() # prints "Hello!"