Fundamentals
Strings
reverse_string = lambda string: string[::-1] # Example usage print(reverse_string("Hello, World!")) # "!dlroW, Hello" print(reverse_string("")) # "" print(reverse_string("a")) # "a" print(reverse_string("ab")) # "ba" print(reverse_string("abc")) # "cba"
def reverse_string(string):return string[::-1]- reverse_string = lambda string: string[::-1]
- # Example usage
- print(reverse_string("Hello, World!")) # "!dlroW, Hello"
- print(reverse_string("")) # ""
- print(reverse_string("a")) # "a"
- print(reverse_string("ab")) # "ba"
- print(reverse_string("abc")) # "cba"
Fundamentals
Logic
def Greeting(n, rank='', formal=0): determinant = f'{rank} {n}' if formal and rank else f'{n}' return f"Hello, {determinant}." if formal else f"Hey, {determinant}!"
- def Greeting(n, rank='', formal=0):
greeting_word = "Hello" if formal else "Hey"rank_str = f", {rank}" if rank and formal else ','period = '.' if formal else '!'return f"{greeting_word}{rank_str} {n}{period}"- determinant = f'{rank} {n}' if formal and rank else f'{n}'
- return f"Hello, {determinant}." if formal else f"Hey, {determinant}!"