Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Other

python notes

Rating
-
Sold
-
Pages
66
Uploaded on
02-12-2025
Written in
2025/2026

this is my self notes on python concepts i have used chatgpt for this .

Institution
Course

Content preview

Python Notes


How to run python codes

1. Interactive Mode in cmd
 Open the command prompt.
 Type python or python3 to start the Python interpreter.

When you write and run Python code in the interactive mode of the Python
interpreter it is not stored permanently anywhere. It exists only temporarily in
memory and is lost when you close the Python session.

To save your Python program for reuse or editing later, you need to Use an
editor like Notepad, VS Code, or PyCharm to write your code.

2. Writing Code in a .py File
 Open a text editor (e.g., Notepad) and write code
 Save that file with .py extension (e.g my_script.py)
 Open the command prompt, navigate to the file's directory using cd, and run:
python my_script.py

3. Using jupyter notebook

, What Is Garbage Collection in Python?


 Garbage collection in Python is an automated memory management process that
deletes objects when they are no longer in use. It uses two methods of garbage
collection: reference counting and generational. Reference counting removes an
object after it reaches zero, and generational garbage collection can break cyclic
references to delete unused objects.


How Memory Management Works in Python

 Python is a dynamically typed language. We don’t declare the type of a variable
when we assign a value to the variable in Python. It states the kind of variable in
the runtime of the program.
 As you can see below, we just assign a variable to an object and Python detects the
type of the object.




What Are Python Objects?

Python objects have three things: Type,value and reference count.
When we assign a name to a variable, Python automatically detects its type. Value is
declared while defining the object. Reference count is the number of names
pointing to that object.

,How Garbage Collection in Python Works
Garbage collection is the process of releasing memory when the object is no
longer in use. This system destroys the unused object and reuses its memory slot
for new objects.
Python has an automated garbage collection process. It has an algorithm to
deallocate objects that are no longer needed. Python has two ways to delete the
unused objects from the memory


2 Methods of Garbage Collection in Python
There are two main ways that Python collects garbage:

Reference counting generational garbage
collection.

1. Reference Counting
In reference counting, references are always counted and stored in memory.
In the example, we assign c to 50. Even if we assign a new variable, the object is
the same. The reference count increases by one. Because every object has its
own ID, we print the IDs of objects to see if they are the same or different.

, When we change the value of a, we create a new object. Now, a points to
60, b and c point to 50.
When we change a to None, we create a none object. Now the previous
integer object has no reference. Garbage collection deletes it.
We assign b to a boolean object. The previous integer object is not deleted
because it still has a reference by c.




Now, we delete c. We decrease the reference count to c by one.




del() statement doesn’t delete objects, it removes the name (and reference) to
the object. When the reference count is zero, the object is deleted from the
system by the garbage collection.
 it’s easy to implement.
 Programmers don’t have to worry about deleting objects when they
are no longer in use.

Written for

Course

Document information

Uploaded on
December 2, 2025
Number of pages
66
Written in
2025/2026
Type
OTHER
Person
Unknown

Subjects

$8.69
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
shraddhachivadshetti

Get to know the seller

Seller avatar
shraddhachivadshetti -
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
1
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions