#
# main.py
# Some Python Program
#
# Created by Mewlan Musajan on 4/27/21.
# Excerpt From: Stochastic Technologies “Tutorial - Learn Python in 10 minutes.” Stavros Korokithakis. https://www.stavros.io/tutorials/python/
#
print(range(10))
rangeList = list(range(10))
print(rangeList)
for number in range(10):
if number in (3, 4, 7, 9):
print("number is in it")
break
else:
continue
else:
pass
if rangeList[1] == 2:
print("the second item is 2")
elif rangeList[1] == 3:
print("the second item is 3")
else:
print("Donno")
while rangeList[1] == 1:
print("We are trapped in an infinite loop!")
break
funcvar = lambda x: x + 1
print(funcvar(1))
def passingExample(someList, someInt, someString = "A default string"):
someList.append("a new item")
someInt = 4
return someList, someInt, someString
someList = [1, 2, 3]
someInt = 10
print(passingExample(someList, someInt))
class SomeClass(object):
common = 10
someVariable = 0
def __init__(self):
self.someVariable = 3
def someFunction(self, someArgument, anotherArgument):
return self.someVariable
someClass = SomeClass()
someClass.someFunction(1, 2)
anotherClass = SomeClass
print(anotherClass.common)
SomeClass.common = 30
class AnotherClass(SomeClass):
def __init__(self, someArgumentment):
self.someVariable = 3
print(someArgumentment)
def someMethod(self, someInt, someString):
someInt += 1
someString += " world"
if someInt == 1:
someInt = "One day,"
else:
someInt = "%s days passed," % someInt
return "%s I said %s to myself." % (someInt, someString)
someAnotherClass = AnotherClass("hello")
print(someAnotherClass.someVariable)
print(someAnotherClass.someMethod(1, "hello"))
def someFunction():
try:
10 / 0
except ZeroDivisionError:
print("Oops, zero can't be a dividend.")
else:
pass
finally:
print("We're done with that.")
someFunction()
import random
print(random.randint(1, 100))
import pickle
someList = ["This", "is", 4, 13327]
someFile = open(r"binary.dat", "wb")
pickle.dump(someList, someFile)
someFile.close()
someFile = open(r"text.txt", "w")
someFile.write("This is a sample string.")
someFile.close()
someFile = open(r"binary.dat", "rb")
loadedlist = pickle.load(someFile)
someFile.close()
print(loadedlist)
list1 = [1, 2, 3]
list2 = [3, 4, 5]
print([x * y for x in list1 for y in list2])
[3, 4, 5, 6, 8, 10, 9, 12, 15]
print([x for x in list1 if 4 > x > 1])
if any([i % 3 for i in [3, 3, 4, 4, 3]]):
print("one of the number is divisible with 3 in the list provide.")
print(sum(True for i in [3, 3, 4, 4, 3] if i == 4))
del list1[0]
print(list1)
del list1
number = 5
def someFunction():
print(number)
def yetAnotherFuncion():
global number
number = 3
someFunction()
yetAnotherFuncion()
print(number)