Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-------------------list------------------
- """""
- num_list = [23, 25,12, 543, 345, 123, 43, 64, 23]
- list1 = [1, 2, 3, 4, 5]
- print(*list1)
- print(list1, sep=" ")
- list1.insert(0, 6)
- list1.append(8)
- list1.extend([1, 2, 3, 4])
- list1.pop(3)
- del list1 [4]
- print(list1, sep=" ")
- """
- #---------------Tuple---------------------
- """""
- my_tuple = 1, "Erasyl", 5.4, True
- print(type(my_tuple))
- print(my_tuple.count('Erasyl'))
- """
- #-------------set-------------------
- """""
- set_a = {1, 2, 3, 4, 5}
- print(type(set_a))
- set_a.add(6)
- set_a.add(5)
- set_a.remove(2)
- print(set_a)
- set_b = {4, 5, 6, 7, 8}
- set_a.union (set_b)
- print(set_a.union(set_b))
- print(set_a | set_b)
- print(set_a.intersection(set_b))
- print(set_a & set_b)
- print(set_a.difference(set_b))
- print(set_a - set_b)
- print(set_a.symmetric_difference(set_b))
- print(set_a ^ set_b)
- """
- #---------------Dictionaries----------------------
- """"
- my_d = {1: 'Test', 'Name': 'Erasyl', }
- my_d[2] = 'Test2'
- print(my_d)
- for key, value in my_d.items():
- print(str(key) + " : " + value)
- """
- #-------------Args and Kwargs-----------------------
- """
- def sum_of(*args):
- sum = 0
- for x in args:
- sum += x
- return sum
- print(sum_of(5, 3, 6))
- def sum_of_k(**kwargs):
- sum = 0
- for key, value in kwargs.items():
- sum += value
- return sum
- print(sum_of_k(coffe = 2.99, cake = 4.33, juse = 2.99))
- """
- #-------------Exceptions-------------------------------
- """
- def divide_by(a, b):
- return a / b
- try:
- ans = divide_by(40, 0)
- except ZeroDivisionError as e:
- print(e, "we connot divide by zero")
- except Exception as e:
- print("Somthing is wrong!", e)
- """
- #--------------------file------------------------------
- """
- file = open('test.txt', mode= 'r')
- data = file.readline()
- print(data)
- file.close()
- with open('test.txt', mode = 'r') as file:
- data = file.readline()
- print(data)
- """
- #------------------create file--------------------------
- """
- with open('newfile.txt', 'w') as file:
- file.write("This is a new file created!")
- with open('newfile.txt', 'w') as file:
- file.writelines(["This is a new file created", "\n This is another line to be added"])
- with open('newfile.txt', 'a') as file:
- file.writelines(["\nThis is a new file created", "\n This is another line to be added"])
- """
- #-----------------reading files--------------------------
- """
- with open('newfile.txt', 'r') as file:
- print(file.read(10))
- with open('newfile.txt', 'r') as file:
- print(file.readline())
- with open('newfile.txt', 'r') as file:
- for x in file:
- print(x)
- """
- #----------------map and filter----------------------------
- """
- menu = ["espresso", "mocha", "latte", "cppuccion", "cortado", "americano"]
- def find_coffee(coffee):
- if coffee[0] == 'c':
- return coffee
- #map---->
- map_coffee = map(find_coffee, menu)
- print(map_coffee)
- for x in map_coffee:
- print(x)
- #filter---->
- filter_coffee = filter(find_coffee, menu)
- print(filter_coffee)
- for x in filter_coffee:
- print(x)
- """
- #----------------class--------------------
- """
- class Myclass():
- a = 5
- def hello(self):
- print("hello, world!")
- myc = Myclass()
- print(myc.a)
- print(myc.hello())
- """
- #----------------class2---------------------
- """
- class Recipe():
- def __init__(self, dish, items, time) -> None:
- self.dish = dish
- self.items =items
- self.time = time
- def contents(self):
- print("The " + self.dish + " has " + str(self.items) + \
- " and takes " + str(self.time) + " min to prepare")
- pizza = Recipe("Pizza", ["cheese", "bread", "tomato"], 45)
- pasta = Recipe("Pasta", ["penne", "sauce"], 55)
- print(pizza.items)
- print(pasta.items)
- print(pizza.contents())
- """
- #-----------------class, instance methods---------------------------
- """
- class Payslips:
- def __init__(self, name, payment, amount) -> None:
- self.name = name
- self.payment = payment
- self.amount = amount
- def pay(self):
- self.payment = "yes"
- def status(self):
- if self.payment == "no":
- return self.name + " is not paid yet"
- else:
- return self.name + " is paid " + str(self.amount)
- Erzhan = Payslips("Erzhan", "no", 1000)
- Samat = Payslips("Samat", "no", 3000)
- print(Erzhan.status(), "\n", Samat.status())
- Samat.pay()
- print(Erzhan.status(), "\n", Samat.status())
- """
- #------------------Parent classes vs child classes--------------------
- """
- class Employees:
- def __init__(self, name, last) -> None:
- self.name = name
- self.last = last
- class Supervisors(Employees):
- def __init__(self, name, last, password) -> None:
- super().__init__(name, last)
- self.password = password
- class Chefs(Employees):
- def leave_request(self, days):
- return "May I take a leave for " + str(days) + " days"
- adil = Supervisors("Adil", "A", "apple")
- enilik = Chefs("Enilik", "E")
- juno = Chefs("Juno", "J")
- print(enilik.leave_request(3))
- print(adil.password)
- print(enilik.name)
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement