tuples=(1,2,4,5)
X,y=tuples
print (X,y)
X,y=tuples
print (X,y)
Anonymous Quiz
48%
ValueError: too many values to unpack (expected 2)
41%
1 [2, 4, 5]
11%
None
By usingsys.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
👍2😁1
👍1
Which tag is used to create a dropdown in HTML Form?
Anonymous Quiz
29%
<input>
43%
<select>
12%
<text>
16%
<textarea>
👍2👎1
What will be the output of the following Python code?
print("abc DEF".capitalize())
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
😁2👍1
What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('yy', 1))
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.
code :
Output:-
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; }
int a = printf("Hello");
printf(", %d", a); return 0; }
Anonymous Quiz
14%
Hello, Hello
12%
5, Hello
27%
Hello, 5
47%
TypeError
Introduction to File Handling
Python provides built-in functions to work with files. The most common operations include:
Opening a file:
Reading from a file:
Writing to a file:
Closing a file:
Syntax:
The
'
'
'
'
'
'
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
Example:
This will open the file
Closing a File
It’s good practice to close a file after you are done with it using the
Alternatively, you can use the
Example:
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