Yes! Python is case sensitive language.
- Numbers
- String
- List
- Tuple
- Dictionary
Question 5- What is the output of print(str) if str="C#Corner"?
String is exactly print using the print() function and output is C#Corner:
- str="C#Corner"
- print(str)
Question 6- What is the output of print str[0] if str = 'C#Corner'?
Only the first letter of string is printed \
- str="C#Corner"
- print(str[0])
Question 7- What is the output of print(str[2:5]) if str = 'C#Corner'?
In this problem, we used the slicing operator in print() function.
Example
- str="C#Corner"
- print(str[2:5])
Output
Question 8- What is the output of print(str[2:]) if str="C#Corner" ?
in this problem, string offset starts from index 2 and executes until the end of the string.
Example
- str="C#Corner"
- print(str[2:])
Output
Question 9- What is the output of print(str*2) if str="C#Corner" ?
In this problem, we used the multiplication operator with the string, which means the string is multiplied by 2 or print the string two times.
Example
- str="C#Corner"
- print(str*2)
Output
Question 10- What is the output of print(str+" community") if str="C#Corner" ?
In this problem, we used the concatenation operator(+), which appends a community at the end of the string.
Example
- str="C#Corner"
- print(str+" community")
Output
Question 11- What is the output of print(list) if list=["python","c#",".net"] ?
It prints the whole list.
Example
- list=["python","c#",".net"]
- print(list)
Output
Question 12- What is the output of print(list[0]) if list=["python","c#",".net"] ?
In this problem, it prints only the first element of the list.
Example
- list=["python","c#",".net"]
- print(list[0])
Output
Question 13- What is the output of print(list[1:3]) if list=["python","c#",".net"] ?
This problem uses a slicing operator, where a starting index is 1 and the ending index is 2.
Example
- list=["python","c#",".net"]
- print(list[1:3])
Output
Question 14- What is the output of print(list[0:]) if list=["python","c#",".net"] ?
In this problem, offset starts from 0 and ends with the length of the list.
Example
- list=["python","c#",".net"]
- print(list[0:])
Output
Question 15- What is the output of print(list*2) if list=["python","c#",".net"] ?
In this problem, we used * operator and the list is repeated two times.
Example
- list=["python","c#",".net"]
- print(list*2)
Output
Question 16- What is the output of print(list+tlist) if list=["python","c#",".net"] & tlist=["c++","php"]?
In this problem, concatenation operator is used with the list and tlist operator combines both the lists.
- list=["python","c#",".net"]
- tlist=["C++","php"]
- print(list+tlist)
Output
Question 17- What is a tuple in Python?
- A tuple is a sequential type data type and it is used to store a value in a sequence.
- A tuple is just like a list in Python but a tuple is a little bit different from a list.
- Tuple values can not be updated after initialization
Example
- tuple=("ajay","python",22)
- print(tuple)
Question 18- What is the difference between tuples and lists in Python?
They are listed below,
Operation |
tuple |
list |
updating |
tuple can't be updated after the declaration |
list can be updated again and again |
declaration |
a tuple is declared using () brackets |
the list is declared using [] brackets |
size |
size of tuple can't be changed |
size of the list can be changed |
|
we can say tuple is a read-only list. |
|
Question 19- What is the output of print(tuple) if tuple = ("c# corner",".net","python","asp","mvc")?
It prints all the elements of a tuple
Example
- tuple=("c# corner",".net","python","asp","mvc")
- print(tuple)
Output
Question 20- What is the output of print(tuple[0]) if tuple = ("c# corner",".net","python","asp","mvc")?
The only first element of a tuple is printed because the index is passed in the print function.
Example
- tuple=("c# corner",".net","python","asp","mvc")
- print(tuple[0])
Output
Question 21- What is the output of print(tuple[1:3]) if tuple = ("c# corner",".net","python","asp","mvc")?
In this problem, only the 2nd and 3rd element is printed.
Example
- tuple=("c# corner",".net","python","asp","mvc")
- print(tuple[1:3])
Output
Question 22- What is the output of print(tuple[2:]) if tuple = ("c# corner",".net","python","asp","mvc")?
It helps to print the second element to the last element.
Example
- tuple=("c# corner",".net","python","asp","mvc")
- print(tuple[2:])
Output
Question 23- What is the output of print(tuple*2) if tuple = ("c# corner",".net","python","asp","mvc")?
In this problem, a tuple prints two times because the tuple is multiplied by 2.
Example
- tuple=("c# corner",".net","python","asp","mvc")
- print(tuple*2)
Output
Question 24- What is the output of print(tuple+tuple1) if tuple = ("c# corner",".net","python","asp","mvc") and tuple1=("c","c++")?
It helps in the concatenation of both the tuples.
Example
- tuple=("c# corner",".net","python","asp","mvc")
- tuple1=("c","c++")
- print(tuple+tuple1)
Output
Question 25- What are Python's dictionaries and how will you create a dictionary in Python?
Dictionaries is one of the datatypes in Python. Dictionaries are having the key and value pair. These are defined, using {} brackets.
Example
- dict={"name":"ajay","sex":"male"}
- print("Name is:",dict["name"])
- print("sex is:",dict["sex"])
Output
Question 26- How will you get all the keys from the dictionary?
In Python programming, we will get all the keys from the dictionary, using keys() method.
Example
- dict={"name":"ajay","sex":"male"}
- print("all keys are:",dict.keys())
Output
Question 27- How will you get all the values from the dictionary?
In Python programming, we will get all the values from the dictionary, using values() method.
Example
- dict={"name":"ajay","sex":"male"}
- print("all values are:",dict.values())
Output
Question 28- How will you convert a string to an int in Python?
In Python programming, we will convert a string into an integer, using int() method.
Example
- str="9999999999"
- number=int(str)
- print("number is:",number)
output
Question 29- How will you convert a string to a float in Python?
In Python programming, we will convert a string into a fractional, using float() method.
Example
- str="10"
- number=float(str)
- print("float number is:",number)
Output
Question 30- How will you sort a list?
In Python programming, we will sort a list, using sort() method.
Example
- list=[50,1,16,2,20]
- print("before sorting",list)
- list.sort()
- print("after softing",list)
Output
Question 31- How will you reverse a list?
In Python programming, we will reverse the list, using reverse() method.
Example
- list=[50,1,16,2,20]
- print("before reverse",list)
- list.reverse()
- print("after reverse",list)
Output
Question 32- How will you remove an object from a list?
In Python programming, we will remove an element from the list, using remove() method.
Example
- list=[50,1,16,2,20]
- print("list before remove",list)
- list.remove(20)
- print("list after remove 20:",list)
Output
Question 33- How will you remove the last object(element) from a list?
In Python programming, we will remove the last element from the list, using pop() method.
Example
- list=[50,1,16,2,20]
- print("list before remove",list)
- list.pop()
- print("list after remove last element:",list)
Output
Question 34- How will you insert an object at a given index in a list?
In Python programming, we will insert an element in a list at a given index, using an insert() method.
Example
- list=[50,1,16,2,20]
- print("list before insert",list)
- list.insert(0,100)
- print("list after insert element at 0 index:",list)
Output
Question 35- How will you get the index of an object in a list?
In Python programming, we will get a given element in a list, using an index() method
Example
- list=[50,1,16,2,20]
- print("index of 16 is:",list.index(16))
Output
Question 36- How will you get the min valued item of a list?
In Python programming, we will get the min valued item of a list, using min() method.
Example
- list=[50,1,16,2,20]
- print("minimum value element is:",min(list))
Output
Question 37- How will you get the max valued item of a list?
In Python programming, we will get the max valued item of a list, using max() method.
Example
- list=[50,1,16,2,20]
- print("maximum value element is:",max(list))
Output
Question 38- How will you get the length of a list?
In Python programming, we will get the length of a list, using len() method.
Example
- list=[50,1,16,2,20]
- print("length of a list is:",len(list))
Output
Question 39- What is the output of list[1:] if list=[50,1,16,2,20]?
In this problem, the list element is printed from the first index to the last index.
example
- list=[50,1,16,2,20]
- print(list[1:])
Output
Question 40- What is the output of print(list[-2]) if list=[50,1,16,2,20]?
In this problem, it helps to print the second to the last element, because a negative index of the last element is -1
Example
- list=[50,1,16,2,20]
- print(list[-2])
Output
Question 41- What is the output of print(list[2]) if list=[50,1,16,2,20]?
In this problem, it helps to print the third element because offset starts from zero(0).
Example
- list=[50,1,16,2,20]
- print(list[2])
Output
Question 42- What is the output of for item in list: print(item) if list=[50,1,16,2,20]?
For loop iterates all the elements from the list.
Example
- list=[50,1,16,2,20]
- for item in list:
- print(item)
Output
Question 43- What is the output of print(2 in list) if list=[50,1,16,2,20]?
This problem "in operator" checks if the given element is present in the list and if it is present, it returns true otherwise false.
Example
- list=[50,1,16,2,20]
- print(2 in list)
Output
Question 44- What is the output of print(list*2) if list=[50,1,16,2,20]?
In this problem, the list is printed twice.
Example
- list=[50,1,16,2,20]
- print(list*2)
Output
Question 45- What is the output of print(list+list1) if list=[50,1,16,2,20] and list1=[100,40]?
This helps to print concatenation of the list and list2.
Example
- list=[50,1,16,2,20]
- list1=[100,40]
- print(list+list1)
Output
Question 46- What is the output of print(len([1, 2, 3]))?
This helps to print 3 because 3 elements is passed into len() method.
Example
Question 47- What is the difference between del() and remove() methods of the list?
remove() method is used to delete a single element from the list.
del() method is used to delete the whole list.
Question 48- How will you check in a string that all the characters are decimal?
In Python programming, we will use isdecimal() method to check in a string if all the characters are decimal or not.
Example
- str="hello welcome in c# corner"
- print(str.isdecimal())
Output
Question 49- How will you convert a string to all uppercase?
In Python programming, we will use upper() method to convert a lowercase string into uppercase.
Example
- str="csharp corner"
- print("string is before used upper method:",str)
- str1=str.upper()
- print("string is after used upper method:",str1)
Output
Question 50- How will you get the title cased version of a string?
In Python programming, we will use title() method to convert a string into a titlecase.
Example
- str="csharp corner"
- print("string is",str)
- str1=str.title()
- print("titlecased string is:",str1)
Output
Question 51- How will you change the case for all the letters in a string?
In Python programming, we will use swapcase() method to change the case of the string.
Example
- str="CSHARP CORNER"
- print("string is",str)
- str1=str.swapcase()
- print("swapcase is:",str1)
Output
Question 52- How will you remove all the leading and trailing whitespace in a string?
In Python programming, we use strip() method to remove all the leading and trailing whitespace in a string.
Example
- str=" CSHARP CORNER "
- print("string is",str)
- str1=str.strip(' ')
- print("after remove whitespace is:",str1)
Output
Question 53- How will you replace all the occurrences of the old substring in string with a new string?
In Python programming, we use replace() method to replace all the occurrences of old substring in a string with a new string.
Example
- str="CSHARP CORNER "
- print("string is",str)
- str1=str.replace("SHARP","#")
- print(str1)
Output
Question 54- How will you get the length of the string?
In Python programming language, we will use len() method to get the length of the string.
Example
- str="c# corner"
- print("length of string is :",len(str))
Output
Question 55- How will you check in a string that all characters are whitespaces?
In Python programming language, we will use isspace() method to check in a string, if all characters are whitespaces or not.
Example
- str=" "
- print(str.isspace())
Output
Question 56- How will you check in a string that all the characters are numerics?
In Python programming language, we will use isnumeric() method to check in a string, if all the characters are numeric or not.
Example
- str="123"
- print(str.isnumeric())
Question 57- How will you check in a string that all the characters are in lowercase?
In Python programming language, we will use islower() method to check in a string if all characters are in lowercase or not.
Example
- str="hello python"
- print(str.islower())
Output
Question 58- How will you check in a string that all the characters are digits?
In Python programming language, we will use islower() method to check in a string if all characters are digits or not.
Example
- str="9999999999"
- print(str.isdigit())
Question 59- How will you check in a string that all characters are alphanumeric?
In Python programming language, we will use isalphanumeric() method to check in a string if all the characters are alphanumeric or not.
Example
- str="n123"
- print(str.isalnum())
Output
Question 60- How will you capitalize the first letter of the string?
In Python programming language, we will use capitalize() method to capitalize the first letter of a string.
Example
- str="python"
- print("string before capatilized",str)
- print("After capitalize",str.capitalize())
Output
Question 61- How will you convert a string to a tuple in Python?
In Python programming language, we will use tuple() method to convert a string to a tuple.
Example
- str="abc"
- tup=tuple(str)
- print("string is:",str)
- print("tuple is:",tup)
Output
Question 62- How will you convert a string to a list in Python?
In Python programming language, we use list() method to convert a string to a list.
Example
- str="abc"
- li=list(str)
- print("string is:",str)
- print("list is:",li)
Output
Question 63- How will you convert a string to a set in Python?
In Python programming language, we use set() method to convert a string to a set.
Example
- str="abc"
- set=set(str)
- print("string is:",str)
- print("set is:",set)
Output
Question 64- How will you create a dictionary, using tuples in Python?
In the Python programming language, we use dict() method to create a dictionary, using tuples.
Example
- tuple=(("name","ajay"),("sex","male"))
- dict=dict(tuple)
- print("tuple:",tuple)
- print("dictionary element is:")
- print("name:",dict["name"])
- print("sex",dict["sex"])
Output
Question 65- What is the use of ** operator?
In Python programming language, ** operator is used to performing an exponential(power).
Example
- a=2
- b=4
- print("2 to power 4: ",a**b)
Output
Question 66- What is the use of // operator?
This operator returns the quotient after the decimal point is removed.
Example
- a=5
- b=2
- print("a/b is:",a/b)
- print("a//b is:",a//b)
Question 67- What is the purpose of is the operator?
Is the operator is used to check if the given string is in another given string or not.
Example
- str="hello"
- str1="hello python"
- print(str in str1)
Output
Question 68- What is the purpose of not in operator?
This statement is used to check if the given variable is not in sequence.
Example
- str="c#"
- str1="hello python"
- print(str not in str1)
Question 69- What is the purpose of a break statement in Python?
The break statement is used to terminate the current loop and resumes execution at the next statement.
Question 70- What is the purpose of the continue statement in Python?
Continue statement is used to reject all the remaining statements in the current iteration of the loop and moves the control back to the top of the loop.
Question 71- What is the purpose of pass statement in Python?
This statement is used, when the statement is needed syntactically but otherwise there is no need for any statement.