Loading...

The Free Online Tutorials, and Always will be.

Python Interview Questions

What is Python ?


Python is a general purpose programming language. which is interpreted, object oriented and high level.
it is used for web applicatons, desktop applications and in data science.

What are the important features of python ?


following are the important features of python :
1. it supports both procedural and object oriented style for writing apps.
2. it provides dynamic data types. which means it check data types at run time.
3. it gives the feature of automatic grabage collection.
4. it is used for multi-platform apps for example it is used in web app, desktop apps etc.

Supported data types in Python ?


following are the supported data types in python are :
1. Numbers - it includes int, float etc
2. String - a string is an array of chars
3. List - list is a collection data type. it use square brackets []
4. Tuple - tuple is a collection data type. it use round brackets ()
5. Dictionary - dictionary is a collection data type. it use curly brackets {}

What is List in Python ?


in python a tuple is a colletion of elements which is ordered and changeable (means we can change it values at any time in the program).
for example:
                                            		
brandslist = ["apple", "samsung", "motorola", "microsoft"]
        			                                
		            	                        

What is Tuple in Python ?


in python a tuple is a colletion of elements which is ordered and unchangeable (means we can not change it once we assign values in it).
for example:
                                            		
brands = ("apple", "samsung", "motorola", "microsoft")
        			                                
		            	                        

What is Set in Python ?


in python a set is a colletion of unique elements which is onordered and unindexed. it removes duplicate entries in it.
for example:
                                            		
brands = {"apple", "samsung", "motorola", "microsoft"}
        			                                
		            	                        

What is Dictionary in Python ?


in python a dictionary is a collection of elements which is in the form of 'key': 'value' pairs. which is unordered and changeable .
we can access data by using key.
for example:
                                            		
productObj = {
"name": "iphone 11",
"brand": "apple",
"model": "64 GB"
}  
        			                                
		            	                        

What is difference b/w lists and tuples in Python ?


in python a list is denoted with square brackets [] whereas tuple is denoted with parentheses ().
list is changeable ordered collection of elements whereas tuple is unchangeable ordered collection of elements.
in list we can grow and shrink elements size at any time in the program whereas in tuple we can not.
in list we can perform read and write operations on it whereas in tuple we can read only.

How we get all the keys in the dictionary in Python ?


in python we can get all the keys by using built-in function keys().
for example:
                                            		
productObj = {
"name": "iphone 11",
"brand": "apple",
"model": "64 GB"
}  
      
print productObj.keys() 

output: 

['name', 'brand', 'model'] 
						      			             
		            	                        

How we get all the values in the dictionary in Python ?


in python we can get all the valuess by using built-in function values().
for example:
                                            		
productObj = {
"name": "iphone 11",
"brand": "apple",
"model": "64 GB"
}  
      
print productObj.values() 

output:

['64 GB', 'apple', 'iphone 11']
	       			                                
		            	                        

How can we convert an Object to a String in Python ?


in python we can convert an object to string by using built-in type casting function str().
simply pass an object to a str() function. in python every thing is an object of its particular type. for example: we convert a dictionary object to string
                                            		
simpleObj = {
"name": "iphone 9",
"brand": "apple",
"model": "64 GB"
}  
      
print str(simpleObj) 

output:

{'model': '64 GB', 'brand': 'apple', 'name': 'iphone 9'}