Hello Python Developer!
How are you? Hope you're in the best condition today. Because we will exercise PyQt WIndow setup.
-PyQt wIndow Size adjustment
- PyQt titlebar & icon setting
Hello Python Developer!
How are you? Hope you're in the best condition today. Because we will exercise PyQt WIndow setup.
-PyQt wIndow Size adjustment
Hello Python developer!
Do you want to code a window base GUI(Graphic User Interface) app like below image?
'PyQt' made by Riverbank Computing and you can find latest news and more details about PyQt from the following link.
PyQt site : https://riverbankcomputing.com/software/pyqt/
For installation of PyQt library at your PC, please type following command in Windows command prompt.
pip install pyqt5
Are you ready for the first PyQt coding?
Let's input following code for PyQt sample and run it!
import sys
from PyQt5.QtWidgets import *
app = QApplication(sys.argv)
label = QLabel(" Hello GUI by Python! ")
label.show()
app.exec_()
Hello Python developer!
Hope you're good today with bright sunshine like our future!
Today, I would like to study Initializer method in Python Class.
Class initializer method was made for initiating class variables and methods.
Think about this, if you create an instance from the class and you want it to have each initiate values and functions.
For instance, we will make a calculator Python program.
First, we will initialize the calculator result variable as 0 with initializer method using ' def __init__(self): ' statement.
Let's look into the following codes.
class Calculator:
def __init__(self):
self.result = 0
def add(self, var1, var2):
self.result = var1 + var2
return self.result
def sub(self, var1, var2):
self.result = var1 - var2
return self.result
test_add = Calculator()
test_sub = Calculator()
print(test_add.add(4, 7))
test_sub.sub(7, 2)
print(test_sub.sub(9,6))
If you want to transfer variables into initializer method, refer following statement.
def __init__(self, var1, var2):
self.first_var = var1
self.second_var = var2
Now, are you familiar with the class 'Initializer' method?
Then, let's analyze following Python exercise codes.
# Python initiate method exercise
class Smartphone:
def __init__(self, model, year): # initiate class 'Smartphone' with following variables and function
self.model = model
self.year = year
self.model_year = model + " " + str(year)
Apple_phone = Smartphone("iPhone 14", 2022)
Samsung_phone = Smartphone("Galaxy S23", 2023)
print(Apple_phone.model, Apple_phone.year)
print(Samsung_phone.model, Samsung_phone.year)
print(Apple_phone.model_year)
print(Samsung_phone.model_year)
Here is above Python source codes in Github(https://github.com/Cevastian/Python-Developer-start-today/blob/master/Python_initiate_method.py)
Hope you get the right answer and level up your Python class understanding.
See you at the next post! Take care!
Hello Python developer!
Today, we will look into class 'inheritance' with my test codes. Because I want to understand about 'class inheritance'.
Let's see following codes and type in Python IDE for execution!
Source codes(Multi_Inheritance.py)
Github link : https://github.com/Cevastian/Python-Developer-start-today/blob/master/Multi_Inheritance.py
class Lion():
color = "yellow"
classification = "animal"
def hunting(self):
print("Lion is hunting")
def attack_claw(self):
print("Claw attack")
class Eagle():
color = "brown"
classification = "bird"
def hunting(self):
print("Eagle is hunting")
def attack_beak(self):
print("Beak attack")
class Shark():
color = "blue"
classification = "fish"
def hunting(self):
print("Shark is hunting")
def attack_teeth(self):
print("Teeth attack")
class Monster(Lion, Eagle, Shark):
color = "green"
classification ="beast"
def playing(self):
print("Monster is playing")
def attack_tail(self):
print("Tail attack")
monster = Monster() # Class instance generating
monster.playing() # monster instance playing method calling
monster.hunting() # monster instance 'Lion' class 'hunting' method by inheritance
monster.attack_teeth() # monster instance 'Shark' class 'attack_teeth' method by inheritance
Executed result
So, 'monster.hunting' method execution result was 'Lion' classes' method excution result. Because there is no 'hunting' method in 'Monster' class so Python search 'hunting' method from the parent classes by 'Lion', 'Eagle' and 'Shark' sequence by Monster(Lion, Eagle, Shark) class inheritance.
Developer, did you understand 'class inheritance' with above example?
Hope you're fine today with Python codes!
Hello, Python developer!
Hope you're fine today! Do you know how can we express the current time in Python program?
Python has 'datetime' module for dealing with the date and time.
Let's test the it with following codes.
Hello Python developer,
Today, I will code Bitcoin price checker with requests module.
Python module is file set of python codes - functions.
I showed module declaration from the Python Glossary
(https://docs.python.org/3/glossary.html#term-module)
import Python module name
We will use 'requests' module for web-scrapping from the 'Binance' cryptocurrency exchange.
Here is the executed result.
There are two ways to print out the Bitcoin price.
- Print content variable from the current_price
- Using JSON module with json function to print out the current Bitcoin price
I also uploaded this code in my GibHub.
I hope you to enjoy above codes.
Have a nice day, Python developer!
Hello, Developer!
Today, I will exercise about Python 'Class'.
Class is based on OOP(Objective Oriented Programming) and I need to exercise it with several examples about class for clear understanding.
Did you remember about 'Class'?
It consists of two parts - Data and Function as following image. Normally, developers call 'data' in class as 'attribute' and 'function' in class as 'method'.
Hello, Python developer!
I would like to introduce "Anaconda" - a Python develop distribution package.
Anaconda distribution package is powerful tools for Python development. It includes several useful toolds and modules for Python programming. It helps you to save time and focus on your Python codes development without searching and installing required Python modules and packages.
Let's install Anaconda package on your PC with following steps.
1. Run the web-browser(i.e. Chrome, Edge, Firefox, Safari and etc.) and connect to Anaconda website with following link.
- Anaconda download link: https://www.anaconda.com/products/distribution
Hello, Developer! Long time no see and I am really pleased to meet you again!
Last 2-years, I had worked differnt field and I was not able to make chance for Python coding... I only had some chances for searching and studying for Python language.
I am really sorry for leaving Python post for a long time. But it's time to coding again!
Today, we will learn the "Python Interpreter".
You can use a Python interpreter as a direct text interactive environment through execution of python interpreter in your operating system(Windows, Mac, Linux, etc.) command prompt mode.
This function helps you can write and test Python codes in interative mode with command lines.
I hope you use this mode for short Python code tests.
Let's test Python codes with interpreter mode.
Hello, Developer! 😄
Today, we will learn the "Inheritance". The "Inheritance" function allows you to use other class functions without codes copy. If you inherit other classes' properties, you can improve programming productivity through this function.
Class Inheritance Form
class Sample_class_name(Inheritance parent class):
def additional_property # You can add additional properties on parents' all properties
def override_property # If you want to override parent properties, you can redefine property with the same property name
I showed all exercise codes and execution result as following.
Chef.py
class Chef:
def make_chicken(self):
print("The chef makdes a chicken.")
def make_salad(self):
print("The chef makes a salad.")
def make_special_dish(self):
print("The chef makes bbq ribs.")
ChineseChef.py
class ChineseChef: # ChineseChef can do everything which Chef can do
def make_chicken(self):
print("The chef makdes a chicken.")
def make_salad(self):
print("The chef makes a salad.")
def make_special_dish(self):
print("The chef makes soup noodle.")
def make_fried_rice(self):
print("The chef makes fried rice.")
InheritanceChineseChef.py
from Chef import Chef
class IchineseChef(Chef):
def make_special_dish(self):
print("The Chef makes a orange chicken.")
def make_fried_rice(self):
print("The Chef makes a fried rice.")
Inheritance.py
from Chef import Chef
from ChineseChef import ChineseChef
from InheritanceChineseChef import IchineseChef
myChef = Chef()
myChef.make_special_dish()
myChineseChef = ChineseChef()
myChineseChef.make_special_dish()
ImyChineseChef = IchineseChef()
ImyChineseChef.make_fried_rice()
Execution Result
Can you see the same result on your PC? Congratulations! Now you can utilize class inheritance function in the Python.
Alright, let's see in the next post, Python developer! 😊
Hello Python developer! How are you? Hope you've been good and had wonderful time with Python. There are 10 Python requests module exerc...