Best Practices


Coding standards

link - peps.python.org/pep-0008/ 


if a_string != "": 
...
# Simplifies to
if a_string:
...


if a_number != 0: 
...
# Simplifies to
if a_number:
...


def check_senior(age: int) -> bool: 
# This `if` statement is unnecessary!
if age > 60:
return True
else:
return False
# Exactly equivalent to
def check_senior(age: int) -> bool:
return age > 60


def check_toddler(age: int): 
# The `== True` part is redundant!
return (age >= 5) == True
def check_toddler(age: int):
# Much better!
return age >= 5


# Defining a function to reverse a string 
def reverse_a_string():
    # Reading input from console
    a_string = input("Enter a string")
    new_strings = []
    
    # Storing length of input string
    index = len(a_string) # Reversing the string using while loop
    while index:
         index -= 1
         new_strings.append(a_string[index])
    
    #Printing the reversed string
    print(''.join(new_strings))
reverse_a_string()




© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext