Python Learning
5.84K subscribers
546 photos
2 videos
85 files
120 links
Python learning resources

Beginner to advanced Python guides, cheatsheets, books and projects.

For data science, backend and automation.
Join πŸ‘‰ https://rebrand.ly/bigdatachannels

DMCA: @disclosure_bds
Contact: @mldatascientist
Download Telegram
What's the output of the code snippet?
❀2
πŸ”₯ is vs == in Python

Many developers confuse these two operators. 
But they check completely different things.

πŸ“Œ == (Equality Operator)

== checks whether values are equal.

a = [1, 2, 3]
b = [1, 2, 3]

print(a == b)


```text
Output:
True


πŸ‘‰ Values are the same 
πŸ‘‰ Even though they are different objects


πŸ“Œ is (Identity Operator)

is checks whether two variables point to the same object in memory.

python
a = [1, 2, 3]
b = [1, 2, 3]

print(a is b)


text
Output:
False


πŸ‘‰ They are stored at different memory locations 
πŸ‘‰ So identity is different


πŸ“Œ When is returns True

python
x = [1, 2, 3]
y = x

print(x is y)


text
Output:
True`


πŸ‘‰ Both reference the SAME object

🎯 Quick Difference

β€’ == β†’ Compares values 
β€’ is β†’ Compares memory identity 
β€’ Use == for value comparison 
β€’ Use is mainly for None checks
❀5
πŸš€ Shallow Copy vs Deep Copy in Python

When copying objects in Python, behavior changes for nested data structures.


πŸ“Œ Shallow Copy

A shallow copy creates a new outer object 
but inner objects remain shared references πŸ”— 

import copy

original = [[1, 2], [3, 4]]
shallow = copy.copy(original)

shallow[0].append(99)

print(original)
print(shallow)


Output:
[[1, 2, 99], [3, 4]]
[[1, 2, 99], [3, 4]]


πŸ‘‰ Nested objects are shared.


πŸ“Œ Deep Copy

A deep copy creates a completely independent copy 
including all nested objects 🧠 

import copy

original = [[1, 2], [3, 4]]
deep = copy.deepcopy(original)

deep[0].append(99)

print(original)
print(deep)


Output:
[[1, 2], [3, 4]]
[[1, 2, 99], [3, 4]]


πŸ‘‰ No shared references.


🎯 Quick Difference

β€’ Shallow β†’ Copies outer layer only 
β€’ Deep β†’ Copies entire structure 
β€’ Use deep copy for nested data
❀4
Forwarded from Programming Quiz Channel
In Python, deepcopy is needed for:
Anonymous Quiz
15%
numbers
13%
strings
16%
tuples
57%
nested objects
Python Memory Model
❀7
🧠 LEGB Rule in Python (Scope Resolution)

When Python looks for a variable, 
it follows a fixed order called LEGB.

L β†’ Local 
E β†’ Enclosing 
G β†’ Global 
B β†’ Built-in 

Python searches in this order.


1️⃣ Local Scope (L) πŸ“ 
Variables defined inside a function.

x = 10

def func():
    x = 5
    print(x)

func()

Output:
5
➀ Python finds x inside the function first.


2️⃣ Enclosing Scope (E) πŸ”„ 
Variables in outer function (nested functions).

def outer():
    x = 20
    def inner():
        print(x)
    inner()

outer()

Output:
20
➀ Python finds x in the enclosing function.


3️⃣ Global Scope (G) 🌍 
Variables defined outside all functions.

x = 30

def func():
    print(x)

func()

Output:
30
➀ Python uses global x.


4️⃣ Built-in Scope (B) βš™οΈ 
Predefined names like len, print, etc.

print(len([1, 2, 3]))

Output:
3

πŸ’‘ Search Order

Local β†’ Enclosing β†’ Global β†’ Built-in 

Python stops searching once it finds the name.
❀3
πŸš€ List vs Tuple in Python

Both store collections of data. 
But they differ in mutability and internal behavior.

1️⃣ List (Mutable) πŸ“¦

Can be modified after creation.

nums = [1, 2, 3]
nums.append(4)
print(nums)

Output:
[1, 2, 3, 4]
➀ How: Stored as a dynamic array 
➀ Wins: Flexible, easy to modify 
➀ Risk: Slightly higher memory usage 

2️⃣ Tuple (Immutable) πŸ”’

Cannot be modified after creation.

nums = (1, 2, 3)
nums.append(4)

Output:
AttributeError: 'tuple' object has no attribute 'append'
➀ How: Fixed-size structure 
➀ Wins: Faster iteration, lower memory usage 
➀ Risk: No modification allowed 

πŸ’‘ Key Difference

β€’ List β†’ Mutable & flexible 
β€’ Tuple β†’ Immutable & lightweight 

Use List when data changes. 
Use Tuple when data should stay constant.
❀5
NumPy Cheatsheet (Basic to Advanced)
❀3
🐍 Let’s Fix How You’re Learning Python

If you feel slow in Python, it usually is not because Python is hard. It is because of the learning approach.

Let me be direct.

⚠️ Avoid these habits

- Jumping between many tutorials
- Copying code without thinking
- Ignoring error messages
- Watching more than building

πŸ‘‰ Instead, build this discipline

- Follow one main learning path
- After every concept, write your own small code
- When an error appears, read it slowly
- Build small projects every week

πŸ“Œ Python becomes easier the moment you start treating it like a tool, not a subject.
❀4
Keywords in Python
❀4
🧠 Learn to Trace Code by Hand

Before running code, pause and predict the output. This builds real understanding.

Consider this:
x = 0

for i in range(3):
x += i

print(x)


Walk through slowly.

1. Start: x = 0

2. i = 0 β†’ x = 0

3. i = 1 β†’ x = 1

4. i = 2 β†’ x = 3

Final output:
3


This habit strengthens your debugging ability more than passive reading ever will.

Try this daily with small snippets.
❀5
Python Basics Cheat Sheet (Beginner Friendly)
❀4
Forwarded from Programming Quiz Channel
Which Python library is the most commonly used for numerical computing and matrix operations?
Anonymous Quiz
12%
Matplotlib
81%
NumPy
5%
Flask
2%
Seaborn
Forwarded from Programming Quiz Channel
Which Python feature allows to modify behavior of other functions?
Anonymous Quiz
50%
Decorators
26%
Iterators
20%
Generators
3%
Closures
🐍 Python Functions (def) βš™οΈ

Functions help organize code into reusable blocks, making programs cleaner and more efficient. Essential for writing modular and scalable code.

πŸ‘‰ They are very important for avoiding repetitive code and building complex applications.

πŸ”Ή 1. What is a Function?

A function is a block of code that only runs when it is called. You can pass data, known as parameters, into a function.

Example:
def greet():
print("Hello from a function!")

πŸ”Ή 2. Defining & Calling a Function

We use the def keyword to define a function, then call it by its name.

Syntax:
def function_name(parameters):
# code to execute
function_name(arguments) # call the function

Example:
def say_hello():
print("Hello, Python learner!")

say_hello() # calling the function

Output: Hello, Python learner!

πŸ”Ή 3. Functions with Parameters & Arguments

Parameters are variables listed inside the parentheses in the function definition. Arguments are the actual values sent when calling the function.

Example:
def welcome_user(name): # 'name' is a parameter
print(f"Welcome, {name}!")

welcome_user("Alice") # "Alice" is an argument
welcome_user("Bob")

Output:
Welcome, Alice!
Welcome, Bob!

πŸ”Ή 4. Return Values

Functions can return data as a result using the return keyword.

Example:
def add_numbers(a, b):
return a + b

result = add_numbers(5, 7)
print(result)

Output: 12

πŸ”Ή 5. Common Function Uses

β€’ Calculations: Performing mathematical operations.
β€’ Data Processing: Transforming inputs.
β€’ User Interaction: Handling prompts and responses.
β€’ Code Reusability: Doing the same task many times.

🎯 Today's Goal

βœ”οΈ Understand what functions are
βœ”οΈ Define and call functions
βœ”οΈ Use parameters and arguments
βœ”οΈ Return values from functions

πŸ‘‰ Functions are fundamental building blocks in almost every Python project.
❀7
Learn Python

This is Scrimba's official Python course featuring their unique interactive scrim format. It offers 58 interactive video lessons where you can pause the screencast and edit the instructor's code directly in your browser with no local setup required. Its great for hands-on learners who want to code actively during the lesson rather than passively watching. No prerequisites are required.

πŸ“š 58 interactive lessons covering Python fundamentals: variables, data types, strings, lists, dictionaries, loops, functions, and file handlingβ€”all with built-in coding challenges

⏰ Duration: 5.6 hours

πŸƒβ€β™‚οΈ Self Paced with immediate start

πŸ† Certificate: Free completion certificate included

Created by πŸ‘¨β€πŸ«: Olof Paulson & Scrimba Team

πŸ”— Course Link


#Python #InteractiveLearning #FreeCertificate

Join Python Learning for more
❀5