Learning basic of python like data type, list, dictionary, function, class, turtle, interface.
Python is a case-sensitive language which is heavily rely on indentation or spacing.
# This is a one-line Python comment - code blocks are so useful!
"""This type of comment is used to document the purpose of functions and classes."""
# Remember values, not variables, have data types.
# A variable can be reassigned to contain a different data type.
answer = 42
answer = "The answer is 42."
boolean = True
number = 1.1
string = "Strings can be declared with single or double quotes."
list = ["Lists can have", 1, 2, 3, 4, "or more types together!"]
tuple = ("Tuples", "can have", "more than", 2, "elements!")
dictionary = {'one': 1, 'two': 2, 'three': 3}
variable_with_zero_data = None
Both lists and tuples are sequence data types that can store a collection of items.
Difference:
lists ---> mutable whereas
tuple ---> immutable.
A mutable data type means that a python object of this type can be modified.
print "Printed!"
cake = "okay"
if cake == "delicious":
print("Yes please!")
elif cake == "okay":
print("I'll have a small piece.")
else:
print("No, thank you.")
for item in list:
print item
while (total < max_val):
total += values[i]
i += 2
There are three ways you can call range() :
- range(stop) takes one argument.
- range(start, stop) takes two arguments.
- range(start, stop, step) takes three arguments.
for i in range(2, 10, 2):
print(i)
print('Goodbye!')
def divide(dividend, divisor):
quotient = dividend / divisor
remainder = dividend % divisor
return quotient, remainder
def calculate_stuff(x, y):
(q, r) = divide(x,y)
print q, r
class Person(object):
def __init__(self, name, age):
self.name = name
self.age = age
def birthday(self):
self.age += 1