Flatten-List

Wed 12 November 2025

def flatten(nested_list):
    flat_list = []
    for item in nested_list:
        if isinstance(item, list):
            flat_list.extend(flatten(item))
        else:
            flat_list.append(item)
    return flat_list

# Example usage
print(flatten([1, [2, 3], [4, [5, 6]]]))  # [1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6]
# Check if a List is Sorted …

Category: python-basics

Read More

For-Loop

Wed 12 November 2025
#  created : 20250125
#  https://www.scientecheasy.com/2022/10/for-loop-in-python.html/
for count in range(0, 5):
    print('You are the high scorer!')
You are the high scorer!
You are the high scorer!
You are the high scorer!
You are the high scorer!
You are the high scorer!
# Program to print …

Category: python-basics

Read More

Frequency

Wed 12 November 2025
def count_frequency(lst):
    frequency = {}
    for item in lst:
        if item in frequency:
            frequency[item] += 1
        else:
            frequency[item] = 1
    print("Element Frequencies:", frequency)

# Example usage
count_frequency([1, 2, 2, 3, 4, 4, 4, 5])
Element Frequencies: {1: 1, 2: 2, 3: 1, 4: 3, 5: 1}

Score: 0

Category: python-basics

Read More

Function-Arguments

Wed 12 November 2025
#  created : 20250321
#  https://www.scientecheasy.com/2022/12/arguments-in-python.html/
# Default Arguments in Python
def studentInfo(name, gender = 'Male'):
# This function displays the student's info passed in the function parameters.
    print('Name:',name)
    print('Gender:',gender)
# Main program.
# Function call 1.
studentInfo('Deepak')
# Function call 2.
studentInfo('Tripti', gender …

Category: python-basics

Read More

Functions

Wed 12 November 2025
print ("hi jerin")
hi jerin
text = 'i am learning'
text
'i am learning'
def add_num():
    one = int(input("enter the nummber"))
    two = int(input("enter another number"))
    total = one + two
    return (f"the total of the number is {total}")
add_num()
enter the nummber 3
enter another number 3





'the total …

Category: python-basics

Read More

Global-Local-Variable

Wed 12 November 2025
#  created : 20250113
#  https://www.scientecheasy.com/2022/09/global-and-local-variables-in-python.html/
#  Global and Local Variables
x = 10 # --> global variable
def numm():
    print("Inside function: ",x)
numm()
print("outside function: ",x)
Inside function:  10
outside function:  10
x = 20 # a global variable.
def my_function():

    x = 20 * 30 # Here, interpreter will treat as …

Category: python-basics

Read More

Identifiers

Wed 12 November 2025
#  created : 20250112
#  https://www.scientecheasy.com/2022/09/identifiers-in-python.html/
#  Identifiers in Python
class = 10
print(class)
  Cell In[2], line 1
    class = 10
          ^
SyntaxError: invalid syntax
class_ = "RSVM"
print(class_)
RSVM
#  identifiers should not include special characters 
school@ = "RSVM"
print(school@)
  Cell In[5], line 1
    school@ = "RSVM"
            ^
SyntaxError …

Category: python-basics

Read More

Identity-Operators

Wed 12 November 2025
#  created : 20250113
#  https://www.scientecheasy.com/2022/10/identity-operators-in-python.html/
#  Identity Is operator (is)
x = 20
y = 20
result = x is y
print(result)
True
str1 = "Python"
str2 = "Python"
result = str1 is str2
print(result)
True
name1 = "John"
name2 = "Jack"
result = name1 is name2
print(result)
False
a = True
b …

Category: python-basics

Read More

If-Else

Wed 12 November 2025
#  created : 20250125
#  https://www.scientecheasy.com/2022/10/if-else-in-python.html/
def num():
    num = int(input("enter the num:"))
    if num % 2 == 0:
        print(num, "is divisible by 2.")
    else:
        print(num, "is not divisible by 2.")
num()
enter the num: 8


8 is divisible by 2.
def marks():
    passMarks = int …

Category: python-basics

Read More

If-Statement

Wed 12 November 2025
#  created : 20250125
#  https://www.scientecheasy.com/2022/10/if-statement-in-python.html/
# Syntax of if Statement in Python
# if test_condition:
#     Python statement(s) to be executed if condition is true.
# or,
# if(test_condition):
#     statement(s)
def per():
    myPer = 92
    if myPer >= 80:
        print("Grade A")
per()
Grade A
def check():
    if(True …

Category: python-basics

Read More
Page 4 of 8

« Prev Next »