PYTHON FOR ABSOLUTE BEGINNERS – PART5

PACKAGES To define a package, needs to create folder, and then inside it create a file as name “__init__.py” Consider that in to_pay.py we have a simple code like: def list_of_payments(): print(“payment”) Now in app.py, we can import this package. import bills.to_pay bills.to_pay.list_of_payments() there is another way: from bills.to_pay import list_of_payments,… list_of_payments() or another way: […]

Python for absolute beginners – Part4

DATA DICTIONARY variable = {“key”: “value”} person = {“name”: “John”, “age”: 23, “city”: “Montreal”} print(person[“age”])  ==> 23 print(person.get(“age”)) ==> 23 person[“country”] = “canada” print(person) ==> {‘name’: ‘john’, ‘age’: 23, ‘city’: ‘montreal’, ‘country’: ‘canada’} print(person.get(“key”, “Key not found!”) ==> Key not found! FUNCTION def function_name( “param” ): def print_some_text(message): the_text = message print(f”The message is: {the_text}”) print_some_text(“a message […]

Python for absolute beginners – Part2

Get data from user and formatted print input(“Message”) print(“Message”) by this code, you ask the users to input some data now let’s improve it. Some converting functions int(x) float(x) bool(x) type(x) len(x)  len(“string”) ==> 6 x.upper()   hi ==> HI x.lower()  Hello ==> hello   string.find(char) q = “Hello” q.find(“e”) ==> 1 x.replace(a,b) q = “Hello There” q.replace(“There”, […]