Cᴏᴅᴇs Sɴɪᴘᴘᴇᴛs
319 subscribers
70 photos
3 videos
3 files
33 links
👩‍💻 Wᴇʟᴄᴏᴍᴇ ᴛᴏ @CodesSnippet! 🚀

Jᴏɪɴ ᴜs ғᴏʀ ᴅᴀɪʟʏ sɴɪᴘᴘᴇᴛs ᴏғ ᴄᴏᴅɪɴɢ 🧩 ᴋɴᴏᴡʟᴇᴅɢᴇ! 💻💡

Hᴇʀᴇ, ʏᴏᴜ'ʟʟ ғɪɴᴅ 👀 ʙɪᴛᴇ-sɪᴢᴇᴅ ᴘɪᴇᴄᴇs ᴏғ ᴄᴏᴅᴇ, 🔥 ᴘʀᴏɢʀᴀᴍᴍɪɴɢ ᴛɪᴘs, ᴀɴᴅ ᴛʀɪᴄᴋs ᴛᴏ ʟᴇᴠᴇʟ ᴜᴘ ʏᴏᴜʀ ᴄᴏᴅɪɴɢ sᴋɪʟʟs! 💪💻

Sᴛᴀʏ ᴜᴘᴅᴀᴛᴇᴅ ᴏɴ ᴛʜᴇ ʟᴀᴛᴇsᴛ ᴛʀᴇɴᴅs ɪɴ ᴛᴇᴄʜ
Download Telegram
By using
sys.getsizeof(), you can easily measure the memory consumption of different data structures, helping you make informed decisions about which to use based on resource availability.


import sys
list1=[1,2,3,4,5]
tup1=(1,2,3,4,5)
print(sys.getsizeof(list1),"bytes")
print(sys.getsizeof(tup1),"bytes")


Output :

104 bytes
80 bytes

[Program finished]

📱 Join us for more Python tips: @CodesSnippet
#pythonhandbook
#pythonbook
#python3
#python
🔥1
Which of the following is a mutable data type in Python?
Anonymous Quiz
22%
Tuple
30%
String
7%
Integer
41%
List
⌨️ Python Quiz
What's the right answer?
Anonymous Quiz
49%
A. Error
30%
B. [3,4,5,6]
13%
C. 3,4,5,6
8%
D. 3
👍2😁1
Guess the correct answer...
Guess the correct option
Anonymous Quiz
35%
0
37%
1
28%
Error
👍1
Which tag is used to create a dropdown in HTML Form?
Anonymous Quiz
29%
<input>
43%
<select>
12%
<text>
16%
<textarea>
a = [1, 2, 3] 
a.append([4, 5])
print(len(a))
👍2
What is the output of the above puthon code
Anonymous Quiz
12%
3
39%
4
41%
5
8%
2
👍2👎1
What will be the output of the following Python code?
print("abc DEF".capitalize())
Anonymous Quiz
10%
abc def
66%
ABC DEF
13%
Abc def
11%
Abc Def
👍1😁1💔1
How to set margin top and bottom in Tailwindcss ?
Anonymous Quiz
23%
mx-1
45%
mt-1
10%
mb-1
23%
my-1
👍1
Python won the "Best Community Support" award. Which year was it recognized for having the most helpful community?
Anonymous Quiz
29%
2000
29%
1991
20%
2010
22%
2007
print((3 > 2) > 1)
Anonymous Quiz
42%
True
37%
False
6%
None
15%
TypeError
😁2👍1
What will be the output of the following Python code?

print("xyyzxyzxzxyy".count('yy', 1))
Anonymous Quiz
43%
2
17%
0
31%
1
10%
none
👍1
Forwarded from Python Codes Basic to Advance (</> ᴍᴜᴋᴇsʜ </>,)
way to create array and perform operation using numpy.
pip install numpy

code :
import numpy as n

# creating array
d=n.array([1,2,3])
d2=n.array([4,5,6])
print(d) #it doesnt seperated with comma
print(d2) #it doesnt seperated with comma
# performing operation
print(d+d2) #it adds the corresponding elements of the arrays
print(d2-d) #it subtracts the corresponding elements of the arrays

print(d*d2) #it multiplies the corresponding elements of the arrays

#similary you can do operation with single element
d3=n.array([10])
print(d*d3)
print(d+d3)
print(d-d3)

Output:-
[1 2 3]
[4 5 6]
[5 7 9]
[3 3 3]
[ 4 10 18]
[10 20 30]
[11 12 13]
[-9 -8 -7]
int main() {
int a = printf("Hello");
printf(", %d", a); return 0; }
Anonymous Quiz
14%
Hello, Hello
12%
5, Hello
27%
Hello, 5
47%
TypeError
number: int = -99
print(-~number)
Anonymous Quiz
7%
-96
32%
-98
16%
-100
45%
99
l = [1, 2, 3]
print(*l)
Anonymous Quiz
33%
1, 2, 3
20%
123
27%
1 2 3
20%
Error
Introduction to File Handling
Python provides built-in functions to work with files. The most common operations include:
Opening a file: open()
Reading from a file:
read(), readline(), readlines()
Writing to a file:
write(), writelines()
Closing a file:
close()

Syntax:
file = open("filename", "mode")

The mode defines how the file will be opened:
'r': Read (default mode, raises an error if the file does not exist)
'w': Write (creates a new file if it does not exist, overwrites existing content)
'a': Append (creates a new file if it does not exist, appends to existing content)
'x': Create (creates a new file, raises an error if the file exists)
'b': Binary mode (e.g., 'rb' for reading binary files)
't': Text mode (default mode, used for reading/writing text files)
Opening and Closing Files
Opening a File

To open a file, use the open() function.

Example:
file = open("example.txt", "r")

This will open the file example.txt in read mode ('r').

Closing a File
It’s good practice to close a file after you are done with it using the close() method. This frees up system resources.
file.close()

Alternatively, you can use the with statement to automatically close the file after the block of code is executed.

Example:
with open("example.txt", "r") as file:
content = file.read()
print(content) # File is automatically closed after the block