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.
withA 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.
importUsed to import modules.
import math
print(math.sqrt(16))
4.0
#57.
from ... importImports 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.
inMembership 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.
delDeletes 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.
passA 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
✨ Quiz: Vector Databases and Embeddings With ChromaDB ✨
📖 Test your knowledge of vector databases and ChromaDB, from cosine similarity and embeddings to querying collections and RAG.
🏷️ #advanced #ai #databases #data-science #machine-learning
📖 Test your knowledge of vector databases and ChromaDB, from cosine similarity and embeddings to querying collections and RAG.
🏷️ #advanced #ai #databases #data-science #machine-learning