Learn Python Coding
38.7K subscribers
1.06K photos
37 videos
24 files
855 links
Learn Python through simple, practical examples and real coding ideas. Clear explanations, useful snippets, and hands-on learning for anyone starting or improving their programming skills.

Admin: @HusseinSheikho || @Hussein_Sheikho
Download Telegram
Quiz: Python Namespace Packages

📖 Practice your knowledge about namespace packages in Python. Revisit managing multiple packages without an __init__.py file.

🏷️ #advanced #python
1
Python's asyncio: A Hands-On Walkthrough

📖 Explore how Python asyncio works and when to use it. Follow hands-on examples to build efficient programs with coroutines and awaitable tasks.

🏷️ #advanced #python
Quiz: Working With Python's .__dict__ Attribute

📖 Practice how Python's .__dict__ attribute works for classes, instances, and functions, and when mappingproxy and __slots__ come into play.

🏷️ #advanced #python
3
Quiz: Deep vs Shallow Copies in Python

📖 Test your understanding of deep and shallow copying in Python. Review assignment, identity, and how to copy complex objects correctly.

🏷️ #advanced #python
Managing Multiple Python Versions With pyenv

📖 Learn how to use pyenv to manage multiple Python versions, prevent conflicts, and keep your projects compatible and development smooth.

🏷️ #advanced #tools
Quiz: Managing Multiple Python Versions With pyenv

📖 Test your knowledge of pyenv with this quiz and see how well you can manage multiple Python versions, virtual environments, and dependencies.

🏷️ #advanced #tools
try:
result = 10 / 0
except ZeroDivisionError:
result = "You can't divide by zero!"
print(result)

You can't divide by zero!


#52. open()
Opens a file and returns a file object.

# This code creates a file named "myfile.txt"
# No direct output, but a file is created.
file = open("myfile.txt", "w")
file.close()
print("File created and closed.")

File created and closed.


#53. .write()
Writes the specified string to the file.

file = open("myfile.txt", "w")
file.write("Hello, File!")
file.close()
# No direct output, but content is written to myfile.txt
print("Content written to file.")

Content written to file.


#54. .read()
Reads the content of the file.

# Assuming "myfile.txt" contains "Hello, File!"
file = open("myfile.txt", "r")
content = file.read()
print(content)
file.close()

Hello, File!


#55. with
A context manager, often used with open() to automatically handle file closing.

with open("myfile.txt", "w") as f:
f.write("This is safer!")
# The file is automatically closed here.
print("File written and closed safely.")

File written and closed safely.

---
#Python #Keywords #Advanced

#56. import
Used to import modules.

import math
print(math.sqrt(16))

4.0


#57. from ... import
Imports specific parts of a module.

from datetime import date
today = date.today()
print(today)

2023-10-27 
(Note: Output date will be the current date)


#58. in
Membership operator. Checks if a value is present in a sequence.

my_list = [1, 2, 3, 4, 5]
print(3 in my_list)
print(10 in my_list)

True
False


#59. del
Deletes an object (variable, list item, dictionary entry, etc.).

my_list = [10, 20, 30]
del my_list[1] # delete item at index 1
print(my_list)

[10, 30]


#60. pass
A null statement. It's used when a statement is required syntactically but you do not want any command or code to execute.

def my_empty_function():
pass # To be implemented later

my_empty_function() # This does nothing and produces no error
print("Function executed without error.")

Function executed without error.


━━━━━━━━━━━━━━━
By: @DataScience4
1
Writing DataFrame-Agnostic Python Code With Narwhals

📖 If you're a Python library developer looking to write DataFrame-agnostic code, this tutorial will show how the Narwhals library could give you a solution.

🏷️ #advanced #data-science #python
2
Quiz: Writing DataFrame-Agnostic Python Code With Narwhals

📖 If you're a Python library developer wondering how to write DataFrame-agnostic code, the Narwhals library is the solution you're looking for.

🏷️ #advanced #data-science #python
2
Quiz: Hands-On Python 3 Concurrency With the asyncio Module

📖 Test your asyncio skills with a focused quiz on coroutines, event loops, generators, and IO-bound concurrency in Python 3.

🏷️ #advanced #python
1