-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlearnings.txt
More file actions
94 lines (75 loc) · 2.77 KB
/
learnings.txt
File metadata and controls
94 lines (75 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
🏋️LEARNINGS
-> ARGS
Amazing explantion here: https://www.programiz.com/python-programming/args-and-kwargs
- *args and **kwargs allow you to pass multiple arguments or keyword arguments to a function.
- *kwargs is for dictionary type
- *args is for tuple
# *args is so you can add as many arguments inside a function without having to proprely write it
# e.g
# info function info(args*) I can then call that function with info("Name", 3, 5) whereas normally I should
# have created the function as such: def info(student_name, age, IQ)
def info(*args):
print(*args)
info("Name", 3, 7) -> returns: Name 3 7
-> KWARGS
# kwargs -> when calling the function if you capitalize the arguments like Name + give it a value
# it transform it into a dictionary
def test(**kwargs):
print(type(kwargs))
print(kwargs)
test(Name="Bap", Age=6) -> returns <class 'dict'>
{'Name': 'Bap', 'Age': 6}
-> ENUMERATE()
enumerate([1,2,3]) -> returns enumerate object number
but when used in a loop, enumerate returns 2 things: the index of the first value and first value itself
list1 = ['hello', 'bye']
print(list(enumerate(list1))) -> returns [(0, 'hello'), (1, 'bye')]
for x, y in enumerate(list1):
print(x)
print(y)
-> returns:
0
hello
1
bye
-> ITEMS()
transform the key-value pairs of a dictionary into tuples in a list.
car = {"brand": "Ford"}
print(car.items())
# returns dict_items([('brand', 'Ford')])
-> UNDERSCORE
In Python, placing an underscore (_) at the beginning of a
variable name is a convention that signals to other developers that the variable is intended for internal use only and should not be
accessed or modified directly from outside of the class, function, or module where it is defined.
In Python, placing an underscore (_) at the beginning of a
function name is a convention that signals to other developers that the
function is intended for internal use only, and should not be used outside of the module where it is defined.
-> CREATE TKINTER
import tkinter as tk
app = tk.Tk()
app.geometry("400x200")
entryExample = tk.Entry(app,
width=5)
entryExample.pack(side=tk.LEFT,
padx=10)
app.mainloop()
# Import the required library
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
# Create an instance of tkinter frame
win=Tk()
# Set the geometry
win.geometry("700x350")
# Add a Scrollbar(horizontal)
h=Scrollbar(win, orient='horizontal')
h.pack(side=BOTTOM, fill='x')
# Add a text widget
text=Text(win, font=("Calibri, 16"), wrap=NONE, xscrollcommand=h.set)
text.pack()
# Add some text in the text widget
for i in range(5):
text.insert(END, "Welcome to Tutorialspoint...")
# Attach the scrollbar with the text widget
h.config(command=text.xview)
win.mainloop()