🐍 Python Basics 6/6: Tricks and Bonuses

date
Mar 31, 2023
slug
python-basics-tricks-and-bonuses
status
Published
tags
Python Basics
summary
Learn some Tricks in Python and save time!
type
Post
Last updated
Mar 31, 2023 12:04 AM
👋 Hoorray!! We have reached our last lesson of Python Basics. Today we will cover just cool tricks to save your time in Python. You deverve it!!
 

 

0) Swapping Variables Values

 
a = 3
b = 4
a, b = b, a

print(f"a: {a}")
print(f"b: {b}")
 

 

1) Declaring Variables with Same Values

 
a = b = c = 5
print(f"a: {a}\tb: {b}\tc: {c}")

a = 2
print(f"a: {a}\tb: {b}\tc: {c}")
 

 

2) Null Value

 
a = None
print(a)
 

 

3) Deleting Variables from Memory

 
a = 5
print(f"a: {a}")

del a
print(f"a: {a}")
 

 

4) Reversing a String

 
my_string = "What's shaking, guys?"
my_reversed_string = my_string[::-1]

print(f"String: {my_string}")
print(f"Reversed String: {my_reversed_string}")
 

 

5) Ordering Lists

 
my_list = [5, 83, 8, 1, 3, 90, 28, 75, 6]
print(f"List: {my_list}")

my_list.sort()
print(f"Sorted List: {my_list}")
 

 
Yeahhhh!! That's all folks!! If you know any othere tricks and tips in Python, feel free to comment this post.
See ya!! 👋