Move-Zero

Wed 12 November 2025

def move_zeroes(lst):
    non_zero = [x for x in lst if x != 0]
    zeroes = [0] * lst.count(0)
    result = non_zero + zeroes
    print("List after moving zeroes:", result)

# Example usage
move_zeroes([0, 1, 0, 3, 12])
move_zeroes([0, 0, 0])
List after moving zeroes: [1, 3, 12, 0, 0]
List after moving …

Category: python-basics

Read More

Multible-Inheritance

Wed 12 November 2025
class Father:
    def skill(self):
        print("Driving")

class Mother:
    def skill(self):
        print("Cooking")

class Child(Father, Mother):
    pass

child = Child()
child.skill()
Driving
class GrandParent:
    def display(self):
        print("GrandParent Display")

class Parent(GrandParent):
    pass

class Child(Parent):
    pass

child = Child()
child.display()
GrandParent Display


Score: 0

Category: python-basics

Read More

Nested-If

Wed 12 November 2025
#  created : 20250125
#  https://www.scientecheasy.com/2022/10/python-nested-if.html/

x = 20
y = 10
z = 5
# Outer if statement.
if x > y:
    if y > z: # Nested inner if statement.
        print('Hello')
Hello
x = 20
y = 10
z = 5
# Outer if statement.
if x > y:
    if y < z: # Nested inner if …

Category: python-basics

Read More

Nested-Loop

Wed 12 November 2025
#  created : 20250125
#  https://www.scientecheasy.com/2022/11/nested-loops-in-python.html/

# Outer for loop.
for x in 1, 2:
    print('Value of x = ',x) # It will execute two times.
  # Inner for loop.
    for y in 1, 2:
        print('Value of y = ',y) # It will execute four times.
print('Nested loops ends …

Category: python-basics

Read More

Operator-Precedence

Wed 12 November 2025
#  created : 20250125
#  https://www.scientecheasy.com/2022/10/operator-precedence-in-python.html/
# Python Precedence Operator
# #  meaning of precedence operator:
# ------------------------------------
# Operator precedence in Python means the order in which the Python interpreter executes operators. 
# It tells the Python interpreter which operator should be evaluated first if a single statement contains more than one …

Category: python-basics

Read More

Overlaoding

Wed 12 November 2025
class Box:
    def __init__(self, length):
        self.length = length

    def __add__(self, other):
        return self.length + other.length

box1 = Box(10)
box2 = Box(20)
print("Total Length:", box1 + box2)
Total Length: 30


Score: 0

Category: python-basics

Read More

Palindrome

Wed 12 November 2025
def check_palindrome(input_string):
    # Check if the string is a palindrome (ignoring case)
    is_palindrome = input_string.lower() == input_string[::-1].lower()

    if is_palindrome:
        return f"{input_string} is a palindrome"
    else:
        return f"{input_string} is not a palindrome"

# Test the function
input_string = "Able was I ere I saw Elba"
print(check_palindrome(input_string))
Able was …

Category: python-basics

Read More

Pass-Statement

Wed 12 November 2025
#  created : 20250316
#  https://www.scientecheasy.com/2022/11/python-pass-statement.html/

x = 20
y = 30
if x > y:
    pass
# there will be no output for this code


Score: 5

Category: python-basics

Read More

Positive-Negative

Wed 12 November 2025
def count_numbers(lst):
    positives = 0
    negatives = 0
    zeros = 0
    for num in lst:
        if num > 0:
            positives += 1
        elif num < 0:
            negatives += 1
        else:
            zeros += 1
    print(f"Positive: {positives}, Negative: {negatives}, Zero: {zeros}")

# Example usage
count_numbers([1, -2, 0, 4, -5, 0])
Positive: 2, Negative: 2, Zero: 2


Score …

Category: python-basics

Read More

Prime-Number

Wed 12 November 2025

def is_prime(num):
    if num <= 1:
        return False
    for i in range(2, int(num**0.5) + 1):
        if num % i == 0:
            return False
    return True

# Example usage
print(is_prime(7))  # True
print(is_prime(10)) # False
True
False


Score: 0

Category: python-basics

Read More
Page 6 of 8

« Prev Next »