Python
Python
What is docstring?
Python docstrings are strings used right after the definition of a function, method, class, or
moduleThey are used to document our code.
Output
{1, 2, 3}
p1 = Person("John", 36)
p1.myfunc()
ou can also use Python For Loop, to iterate over each element of range, and then append the item to list.
list1 = list()
for x in range(2, 20, 3):
list1.append(x)
print(list_1)
What are the built-in functions that are used in Tuple?
len(),
max(),
min(),
tuple(),
index(),
count(),
sum(),
sorted()
del dict1["black"]
print(dict1)
str="aaa"
palindromChecker(str)
9. Write a Python program to remove all duplicates from the given string in Python.
def duplicate(str):
newStr=""
for char in str:
if char not in newStr:
newStr=newStr+char
return newStr
str="helllo world"
print(duplicate(str))
checkLeap(2005)
fibonacii(4)
# order of number
order = len(str(num))
# initialize sum
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** order
temp //= 10
if num == sum:
print(num)
print(sumOfNatural(-1))
20. Write a Python program to copy the contents of a file to another file.
with open("file1.txt","r") as file1,open("file2.txt","a") as file2:
for line in file1:
file2.write(line)
21. Write a program that accepts sequence of lines as input and prints the lines after
making all characters in the sentence capitalized.