Python-Literals

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

# String literals
# Numeric literals
# Boolean literalsb
# Literal Collections
#  single line string
sigle_line_string = 'Welcome \
to \
Scientech Easy'
print(sigle_line_string)
Welcome to Scientech Easy
multi_line_string = '''Welcome \
to \
Scientech Easy, \
Dhanbad'''
print(multi_line_string)
Welcome to Scientech Easy, Dhanbad …

Category: python-basics

Read More

Python-Tokens

Wed 12 November 2025
#  created : 20250113
#  https://www.scientecheasy.com/2022/09/python-tokens.html/
#  python tokens
# Keywords (Reserved words) : True, False, None, class, continue, break, if, elif, else, from, or, def, del, import, etc.
# Identifier : User-defined names
# Literals : String, Numeric, Boolean, Collection,
# Delimeters : ( ), { }, [ ], :, ., =, ;, +=, -=, *=, /=, %=, etc.
# Operators : +, -, *, **, /, %, <<, >>, etc.
x = int(input("Enter your first number = ")) # --> in …

Category: python-basics

Read More

Replace-Negative

Wed 12 November 2025

def replace_negatives(lst):
    replaced = [x if x >= 0 else 0 for x in lst]
    print("List after Replacing Negatives:", replaced)

# Example usage
replace_negatives([-1, 2, -3, 4, -5])
List after Replacing Negatives: [0, 2, 0, 4, 0]
# intersection of a list 
def list_intersection(lst1, lst2):
    intersection = [x for x in …

Category: python-basics

Read More

Reversed-Keyword

Wed 12 November 2025
#  created : 20250111
#  https://www.scientecheasy.com/2022/09/reserved-keywords-in-python.html/
import keyword
print(keyword.kwlist)
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield …

Category: python-basics

Read More

Second-Large-Numbers

Wed 12 November 2025

def second_largest(numbers):
    if len(numbers) < 2:
        return "Error: List must have at least two distinct numbers."

    # Remove duplicates
    unique_numbers = list(set(numbers))

    if len(unique_numbers) < 2:
        return "Error: Not enough distinct numbers to determine the second largest."

    # Sort the unique numbers in descending order
    unique_numbers.sort(reverse=True)

    # Return …

Category: python-basics

Read More

Sum-Positive

Wed 12 November 2025
def sum_positives(lst):
    positive_sum = sum(x for x in lst if x > 0)
    print("Sum of Positive Numbers:", positive_sum)

# Example usage
sum_positives([-1, 2, 3, -4, 5])
Sum of Positive Numbers: 10
def shift_list(lst, k):
    k = k % len(lst)  # Handle shifts larger than list length
    shifted = lst[-k:] + lst …

Category: python-basics

Read More

Switch-Statement

Wed 12 November 2025
#  created : 20250321
#  https://www.scientecheasy.com/2022/11/switch-statement-in-python.html/
#  Implementing Switch Statement in Python using If-Elif-Else
city = 'd' # Initialize the variable.
if city == 'm':
    print('Mumbai')
elif city == 'd':
    print('Dhanbad')
elif city == 'c':
    print('Chennai')
elif city == 'r':
    print('Ranchi')
else:
    print('No city')
Dhanbad
# Implementing Switch Statement …

Category: python-basics

Read More

Templates

Wed 12 November 2025
import pyutil as pyu
pyu.get_local_pyinfo()
'conda env: py311; pyv: 3.11.9 (main, Apr 19 2024, 16:48:06) [GCC 11.2.0]'
print(pyu.ps2("pandas"))
pandas==2.2.3



Score: 0

Category: pandas-work

Read More

Ternary-Operator

Wed 12 November 2025
#  created : 20250113
#  https://www.scientecheasy.com/2022/10/ternary-operator-in-python.html/
#  Ternary Operator in Python
x =  10 
y = 20 


if(x > y):
    msg = 'Hello'
else:
    msg = 'Goodbye'
print('Hello' if True else 'Goodbye') 
print('Hello' if False else 'Goodbye') 
Hello
Goodbye
x, y = 20, 40
z = 20 if (x > y) else …

Category: python-basics

Read More

Typing-Module

Wed 12 November 2025
#  created : 20251112
# https://stevejoe1412.gitbook.io/ssn/python-subtopics/1.-typing-module
from typing import List

def sum_of_integers(numbers: List[int]) -> int:
    return sum(numbers)

print(sum_of_integers([1, 2, 3]))  # Output: 6
6
from typing import Optional

def greet(name: Optional[str] = None) -> str:
    if name:
        return f"Hello, {name}!"
    return "Hello …

Category: python-basics

Read More
Page 9 of 10

« Prev Next »