Open TobiaszFuczek opened 1 year ago
Ad. Interview questions:
Python Benefits 1.1. Objects, Modules
def(self, car_make, years_of_production):
self.car_make = car_make
self.years_of_production = years_of_production
def your_name(self):
return f"I am car make {self.car_make}, years of production: {self.years_of_production}"
1.2. Exeptions
try:
result = a / b
return result
except ZeroDivisionError:
print("Błąd: Dzielenie przez zero!")
return None
except TypeError:
print("Błąd: Nieprawidłowy typ danych!")
return None
1.3. Automatic Memory Management
#Tworzenie listy zawierającej milion liczb od 0 do 999999
my_list = list(range(1000000))
#Przykład użycia obiektów z listy
sum_of_numbers = sum(my_list)
average = sum_of_numbers / len(my_list)
print("Średnia liczb:", average)
1.4 Python is a open-source language because is open for all . His access is open for free for all and his open-source is available access public and can be modificate.
2.PEP 8
Standard library imports. Related third party imports. Local application/library specific imports.
Naming Convention: use snake_case for name function, variables, method f eg. my_car use CamelCase for name class f. eg MyClass
White Space:
# Correct:
spam(ham[1], {eggs: 2})
# Wrong:
spam( ham[ 1 ], { eggs: 2 } )
Documentation: use docstrings and use inside comment to desription difficult snippents code
def factorial(n):
'Oblicza silnię liczby n.
Silnia liczby n jest iloczynem wszystkich liczb całkowitych od 1 do n.
Argumenty:
n (int): Liczba, dla której obliczana jest silnia.
Zwracane wartości:
int: Silnia liczby n.
'
if n == 0:
return 1
else:
result = 1
for i in range(1, n + 1):
result *= i
return result
# Wywołanie funkcji i wyświetlenie docstringu
print("Docstring dla funkcji factorial:")
print(factorial.__doc__)
# Obliczenie i wyświetlenie silnii dla liczby 5
print("Silnia liczby 5 to:", factorial(5))
import pickle
data = [1, 2, 3, 4, 5]
with open('data.pickle', 'wb') as file: pickle.dump(data, file)```
import pickle
with open('data.pickle', 'rb') as file: loaded_data = pickle.load(file)
print(loaded_data) # Wyświetli: [1, 2, 3, 4, 5]
4.Python language is interpreted language, what that is mean, source code is a procesing and executing immediately for the interpreter.
5.Memory manage in Python
`
x = [1, 2, 3]
y = x
x = None
`
Create List
assigning a reference to the same list
reference None to the variable x, wchich cut to the reference to the list
def calculate_square(x):
result = x * x
return result
num = 5 print("Kwadrat liczby", num, "to", calculate_square(num))
3.We can generate pylint in terminal give name the file: pylint example.py
-pychecker currently is not using in programming world
7.Decorators
def wrapper():
print("Something is happening before the function is called.")
func()
print("Something is happening after the function is called.")
return wrapper
@my_decorator
def say_hello():
print("Hello!")
say_hello()
This example we have a function my_decorator() who take function func() as argument and return function inside wrapper(). Then apply this dekorator to function say_hello() with @my_decorator.
8.Different lists and tuple
my_tuple = (1, 2, 3)
my_list = [4, 5, 6]
my_dict = {
my_tuple: "To jest krotka",
my_list: "To jest lista"
}
tuple_key = (1, 2, 3)
print(my_dict[tuple_key])
list_key = [4, 5, 6]
print(my_dict[list_key])
Tuple can use in dictionary, the tuple is immutable bat lists are mutable, what allow in changing value in list.
10.Dict and Lists comprehensions
words = ["Apple", "Banana", "Cherry"]
lowercase_words = [word.lower() for word in words]
print(lowercase_words) # Wyświetli: ['apple', 'banana', 'cherry']
fruits = ["apple", "banana", "cherry", "date"]
lengths_dict = {fruit: len(fruit) for fruit in fruits}
print(lengths_dict) # Wyświetli: {'apple': 5, 'banana': 6, 'cherry': 6, 'date': 4}
Example 1: Create new list with using list words[]. Example 2: Crate dictionary with using list fruits[]
Mutable built-in types are:
List Sets Dictionaries Immutable built-in types Strings Tuples Numbers Immutable built-in types are:
Strings Tuples Numbers
15.Pass- in following example pass is as empty function but the code will perform in correct.
def empty_function():
pass
my_list = [1, 2, 3, 4, 5]
my_iterator = iter(my_list)
print(next(my_iterator))
my_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
sublist = my_list[2:5]
print(sublist)
def calculate_square(x):
"""
Calculate the square of a number.
Args:
x (int or float): The input number.
Returns:
int or float: The square of the input number.
"""
return x ** 2
print(calculate_square.__doc__)
DoD ✅
fuel consumption
is implemented and is tested according to the user stories,fuel consumption
is approved by the Client, [JR: to be remove, let's keep the quality requirements in DoD only]fuel consumption
app is prepared and approved,Description ✉️ - practice
User Stories 📖
Prepare the fuel consumption` app according to the following user stories:
The app should not save the data in the DB, it's allowed to store the data in the memory. Please prepare the written technical desing the app, which would contain the following elements:
Please be creative, and try to propose nice solution which would satisfy our Client's needs 🚀 🧠
Scope 📦
Use Case:
Description ✉️ - theory
Interview questions ❓
Please, be prepared for the following questions: 1, 2, 3 (please prepare practical example - code snippet in the task description), 4, 5, 6,7, 8, 9, 10, 11 (please prepare practical example - code snippet in the task description), 12, 15, 16, 18 (please prepare practical example - code snippet in the task description), 20:
List of Questions
[JR: Whare are the answers with the code snippents?]
Data structure in practice 🏳
Data Structures v1 Data Structures v2
[JR: Whare are the answers with the code snippents?]
Good luck 🤞 .
All of the processes related to the GIT/Task workflow must be performed.