Conditions:if, else and elif
Allows you to excute diff blocks of code depending on whether the cond is
true or false
Ternary operator: a short way of writing if – else statement in one line
Age=20
Status= “adult ” if age>= 18 else “minor”
Print(status)
Variables stores data python will now by its own about the data type
Loops for and while
Iterate :repeated execution of certain statements
For; iterates over a list,string
While : continues as long as the statement is correct
Operators
Arithmetic; assignment(+=,..);comparison;logical(and,or, not);identity (is,
is not);membership(in, not in)
Bitwise operators
And(&), or(|), xor (^),not(~), left shift(<<):shifts the bits to left by the
specified number of positions. This effectively mulitplies the number by
powers of 2
Like 5<<1 #0101<<1 = 1010(10) output is 10
And right shift (>>) : to right side and … effectively divides …
Like 5>>1 #0101 >>1 =0010(2)
Functions
Block of code runs when it is called. We can pass data(parameters)and it
gives a output
Parameters and arguments
Parameters: the variable int the fn def that receives the input (variables in
fn defination)
Arguments: the actual value or expression passed to fn when calling it
(passed to the fn when called)
And there are diff types of arguments : positional , key word, default, and
variable-length
def add(*args):
return sum(args)
print(add(1, 2, 3)) # Output: 6
def display_info(**kwargs):
for key, value in kwargs.items():
print(f"{key}: {value}")
display_info(name="Alice", age=25)
# Output:
# name: Alice
# age: 25
Recursion: fn that calls itself to solve a prblm
Python has a limit for recrusive calls, which defaults to 1000. If it exceeds,
it will throw a RecursionError
Lambda fn: anonymous defined using lambda keyword
Square= lambda x: x**2
Result = square(4) #16
Base case is essential to prevent infinite recursion
Higher order fn’s:
map()-applies a given fn to each item in an iterable (like a list)
memorization-optimization technique used to store results of expensive fn
calls and reuse them when the same inputs occur again
closures
def apply_function(f, values):
return [f(x) for x in values]
# Example function to square a number
def square(x):
return x * x
# Test the higher-order function
values = [1, 2, 3, 4]
print(apply_function(square, values)) # Expected output: [1, 4, 9, 16]
1. Build Cool Projects (Learn by Doing)
The best way to stay motivated while learning Python is by building things
that are interesting to you. Here's how you can learn as you go:
Start with small projects: Think of something small but fun to
build, like a simple calculator, a to-do list app, or a quiz game.
These will help you get a feel for the language and practice basic
concepts.
Game development: Try creating a simple game using the
Pygame library. Building a game, even a basic one, is a really fun
way to learn about Python. Start with something simple like tic-tac-
toe, and then progress to something more complex like snake or
pong.
Web scraping: Learn to use BeautifulSoup or Selenium to
scrape websites. You can collect data that interests you and use it
for personal projects like tracking sports statistics, collecting quotes,
or scraping data for a research project.
Automating daily tasks: If you have repetitive tasks like renaming
files, sending emails, or organizing your desktop, learn to automate
those tasks using Python. This practical use of Python will show you
the power of automation and keep it engaging.
Example Projects:
Create a chatbot using Python's NLTK (Natural Language Toolkit).
You can program it to answer questions or give advice.
Build a weather app that pulls data from an API and shows
weather information for a location you input.
2. Learn Through Games and Challenges
Making the learning process feel like a game or a challenge can keep you
motivated.
Code Combat – CodeCombat
o Why it’s fun: CodeCombat turns learning Python into a real-
time game. You write Python code to control characters and
navigate through challenges. You level up as you solve
puzzles.
o Benefit: You’re learning syntax, problem-solving, and
algorithms while progressing through fun, interactive levels.
Checkio – Checkio
o Why it’s fun: This is another gamified platform where you
solve coding challenges using Python. It’s beginner-friendly
but also offers a wide range of progressively harder problems.
o Benefit: The challenges are fun and come with a lot of
feedback, and you can see how others solved the same
problems.
Exercism – Exercism
o Why it’s fun: Exercism offers Python practice exercises with
a mentor feature. You can get feedback on your solutions and
learn better ways to approach problems.
o Benefit: It’s like a personal coding coach helping you improve
your skills with challenging tasks.
3. Interactive Learning Platforms
These platforms keep you engaged with interactive coding exercises and
immediate feedback.
LeetCode – LeetCode Python
o Why it’s fun: LeetCode offers coding challenges that allow
you to solve problems using Python, from simple to very
complex. It's challenging, and solving problems feels very
rewarding. It’s perfect for improving algorithm skills while
having fun.
o Benefit: As you solve harder problems, you get better at
logic, algorithms, and data structures. Plus, it's a great way to
prepare for technical interviews if you're interested in that.
HackerRank – HackerRank Python
o Why it’s fun: HackerRank has Python tutorials and
challenges with specific tracks (like algorithms, data
structures, and problem-solving). It gives you instant feedback
and explanations.
o Benefit: It's a way to see how much you've progressed and
also compete with others. Some challenges have
leaderboards, which adds a sense of accomplishment.
4. Follow Tutorials and YouTube Channels
Sometimes watching someone else explain concepts can make them more
relatable and fun. You can follow along with tutorials and learn by doing:
Tech With Tim (YouTube) – Tech With Tim
o Why it’s fun: Tim offers hands-on tutorials in Python,
focusing on interesting topics like game development,
automation, and machine learning. His tutorials are clear and
easy to follow.
Python Crash Course (Book + Video Tutorials) – Python Crash
Course
o Why it’s fun: This is an excellent book for learning Python
with a focus on building real projects. It takes you step-by-
step, from basic concepts to creating projects like games and
web apps.
Corey Schafer (YouTube) – Corey Schafer’s Python Tutorials
o Why it’s fun: Corey Schafer’s YouTube channel has high-
quality Python tutorials, covering everything from the basics
to more advanced topics. His videos break concepts down into
understandable chunks.
5. Learn Python with Real-Life Applications
If you're passionate about something, learning Python in the context of
that area will make it more interesting. Here are some ideas:
Data Science: If you’re interested in data or analytics, Python is
the go-to language. You can start learning Python libraries like
Pandas and Matplotlib for data analysis and visualization.
Machine Learning: Use Python’s Scikit-learn, TensorFlow, or
Keras libraries to get started with building machine learning
models. This can be a very rewarding experience, especially if you
like working with data and algorithms.
Web Development: Learn how to build websites using Flask or
Django. By building a personal website or a web app, you’ll learn
Python and create something you can be proud of.
Internet of Things (IoT): If you're interested in hardware, try
using Python with Raspberry Pi or Arduino. You can build gadgets
or smart devices and control them using Python.
6. Stay Consistent, But Take Breaks
Learning a new language can be overwhelming if you dive into it all at
once. Instead, break your learning into manageable chunks:
Set aside 30 minutes to 1 hour each day for learning and practice.
Consistency is key.
Don’t hesitate to take short breaks. Step away for a bit, and come
back with fresh energy.
This method keeps the pressure low and allows you to digest what you’ve
learned before moving on to the next step.
7. Find a Community
Being part of a community can keep you motivated and make learning
Python less isolating.
Reddit - Python Subreddit: r/learnpython
Stack Overflow: Get involved in the Python community by helping
others with their questions and discussing solutions.
Discord / Slack Python Communities: Many online communities
have dedicated channels where you can discuss Python topics and
share projects.
In Summary:
1. Start with Fun Projects: Build apps, games, and automation tools.
2. Use Gameified Learning: Platforms like CodeCombat, Exercism,
and Checkio turn learning into a game.
3. Interactive Platforms: Leverage HackerRank and LeetCode for
hands-on challenges.
4. Follow Fun YouTube Channels: Explore creators like Corey
Schafer and Tech With Tim.
5. Build Real-Life Applications: Dive into data science, web
development, or IoT projects.
6. Stay Consistent and Take Breaks: Small daily practice is better
than cramming.
7. Join a Community: Connect with others to stay motivated and get
feedback.