PWP 2 MARKS
PWP 2 MARKS
Easy to Learn and Use Interactive Mode Expressive Languag Interpreted Language
Cross-platform Language Portable Free and Open Source Object-Orient
Example:
class Student:
def __init__(self):
self.name = "Unknown"
def show(self):
print("Name:", self.name)
s1 = Student()
s1.show()
Output:
Name: Unknown
5. Describe Multiline comment in python.
A multiline comment in Python is typically written using triple quotes (''' or """) to span multiple lines,
though it's technically a multiline string, not an actual comment. For actual comments, multiple lines starting
with # are used.
Example:
'''
This is a multiline comment
using triple quotes.
'''
# Or
# This is a
# true multiline comment
# using hash symbols.
11.State the use of read() and readline () functions in python file handling.
Use of read() and readline() in Python File Handling:
read():
Reads the entire content of a file as a single string. You can also specify the number of characters to read.
my_list = [1, 2, 3]
my_list.append(4)
print(my_list) # Output: [1, 2, 3, 4]
2. Using extend():
Adds multiple elements (from another iterable like a list or tuple) to the end of the list.
my_list = [1, 2, 3]
my_list.extend([4, 5])
print(my_list) # Output: [1, 2, 3, 4, 5]
3 in [1, 2, 3] # True
17.What is dictionary?
Dictionary in Python:
A dictionary is a built-in Python data type that stores data in the form of key-value pairs.
Definition:
A dictionary is used to store multiple items where each item has a key and a value. It is mutable, unordered (as
of Python <3.7), and indexed by keys.
Example:
student = {
"name": "John",
"age": 20,
"grade": "A"
}
my_list = [1, 2, 3, 4]
print(3 in my_list) # Output: True
2. not in Operator
o Returns True if the specified element is not present in the list.
o Example:
# This is a comment
Multi-line Comment: Use triple quotes (''' or """) for multi-line comments.
'''
This is a
multi-line comment
'''