Class-Docstring

Wed 12 November 2025
#  created : 20250113
#  https://www.scientecheasy.com/2022/09/docstring-in-python.html/
#  class docstring
class Rectangle:
    """
    This is a class for calculating the area of a rectangle.

        Parameters:
        l (int) : The length of rectangle.
        b (int) : The breadth of rectangle.
    """
print(Rectangle.__doc__)
    This is a class for calculating the area of …

Category: python-basics

Read More

Class-Keyword

Wed 12 November 2025
#  created : 20250111
#  https://www.scientecheasy.com/2022/09/reserved-keywords-in-python.html/
#  class Keyword
#  example for a class declarstion 
class ClassExample:
    def func1(parameters):
        . . . .
    def func2(parameters):
        . . . .
with open('myfile.txt', 'w') as file:
    file.write('Hi jerin!')
#  as Keyword
import math as x
print(x.cos(0))
1.0
#  pass keyword …

Category: python-basics

Read More

Class-Object

Wed 12 November 2025
class Car:
    def __init__(self, brand, model):
        self.brand = brand
        self.model = model

    def display_info(self):
        print(f"Car Brand: {self.brand}, Model: {self.model}")


my_car = Car("Toyota", "Corolla") # ---> this is the object for that class
my_car.display_info()
Car Brand: Toyota, Model: Corolla


Score: 0

Category: python-basics

Read More

Collection-Literals

Wed 12 November 2025
#  created : 20250112
#  https://www.scientecheasy.com/2022/09/literals-in-python.html/
#  Collection literals in Python

#  List literals
address = ['Scientech Easy', 'Joraphatak Road', 'Dhanbad']
print(address)
['Scientech Easy', 'Joraphatak Road', 'Dhanbad']
num = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print(num)
[1, 2, 3, 4, 5, 6, 7, 8 …

Category: python-basics

Read More

Comparison-Operators

Wed 12 November 2025
#  created : 20250113
#  https://www.scientecheasy.com/2022/10/comparison-operators-in-python.html/
#  Comparison  Operators
# Equal to (==)
x = 20
y = 20
print( x == y)
True
p = 'My name is John'
q = 'My name is John'
print( p == q)
True
r = 'Text'
s = 'text'
print( r == s)
False
t = [1, 2, 3, 4]
u …

Category: python-basics

Read More

Continue-Statement

Wed 12 November 2025
#  created : 20250316
#  https://www.scientecheasy.com/2022/11/python-continue.html/
# Syntax of Continue Statement in Python
for letter in 'Technology':
    if letter == 'n':
        print('Skipping the loop at', letter)
        continue
    print(letter)
T
e
c
h
Skipping the loop at n
o
l
o
g
y
for x in range …

Category: python-basics

Read More

Datet-Ime

Wed 12 November 2025
from datetime import datetime

def string_to_date(date_string):
    date_object = datetime.strptime(date_string, "%Y-%m-%d")
    return date_object

# Example usage
date_string = "2025-01-02"
result = string_to_date(date_string)
print(result)
2025-01-02 00:00:00
def check_leap_year(year):
    if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
        return "Leap year"
    else …

Category: python-basics

Read More

Def-Keyword

Wed 12 November 2025
#  created : 20250111
#  https://www.scientecheasy.com/2022/09/reserved-keywords-in-python.html/
#  def keyword
def func():
    print("Inside Function")
func()
Inside Function
#  return keyword
def func_return():
    x = 20
    return x

def func_no_return():
    y = 50

    return y
print(func_return())
20
print(func_no_return())
50
def func():
    x = 0
    for i in range(5):
        x …

Category: python-basics

Read More

Diamond-Problem

Wed 12 November 2025
class A:
    def display(self):
        print("hello jerin")

class B(A):
    pass

class C(A):
    pass

class D(B, C):
    pass

d = D()
b = B()
b.display()
d.display()
hello jerin
hello jerin


Score: 0

Category: python-basics

Read More

Dict-Merge

Wed 12 November 2025
def merge_dicts():
    # Define the two dictionaries inside the function
    my_dict1 = {'a': 1, 'b': 2, 'c': 3}
    my_dict2 = {'d': 4, 'e': 5, 'f': 6}

    # Method 1: Using dictionary unpacking
    result1 = {**my_dict1, **my_dict2}
    print("Method 1:", result1)

    # Method 2: Using copy and update
    result2 = my_dict1.copy()
    result2.update(my_dict2)
    print("Method 2 …

Category: python-basics

Read More
Page 2 of 8

« Prev Next »