Python Programming Language – Complete Explanation
1. Introduction to Python
Python is a high-level, interpreted, object-oriented programming language created by Guido van Rossum in 1991.
It is designed to be simple, easy to learn, and powerful. Python emphasizes readability and productivity, making it one of the most popular programming languages in the world today.
-
Creator: Guido van Rossum
-
Year of Release: 1991
-
Current Version (2025): Python 3.x (Python 2 is discontinued)
-
Official Website: python.org
2. Features of Python
Python is widely used because of its unique features:
-
Simple and Easy to Learn – Python syntax is close to English.
-
Interpreted Language – No need for compilation, runs line by line.
-
Cross-Platform – Works on Windows, Linux, macOS, etc.
-
Object-Oriented – Supports classes, objects, inheritance, and polymorphism.
-
Dynamic Typing – No need to declare variable types explicitly.
-
Huge Standard Library – Provides built-in modules for math, OS, web, etc.
-
Open Source – Free to use and modify.
-
Portable – Python programs can run anywhere without changes.
-
Extensible – Can integrate with C, C++, Java, etc.
-
Popular for AI and Data Science – Huge support with libraries like TensorFlow, Pandas, NumPy.
"This Content Sponsored by SBO Digital Marketing.
Mobile-Based Part-Time Job Opportunity by SBO!
Earn money online by doing simple content publishing and sharing tasks. Here's how:
- Job Type: Mobile-based part-time work
- Work Involves:
- Content publishing
- Content sharing on social media
- Time Required: As little as 1 hour a day
- Earnings: ₹300 or more daily
- Requirements:
- Active Facebook and Instagram account
- Basic knowledge of using mobile and social media
For more details:
WhatsApp your Name and Qualification to 9994104160
a.Online Part Time Jobs from Home
b.Work from Home Jobs Without Investment
c.Freelance Jobs Online for Students
d.Mobile Based Online Jobs
e.Daily Payment Online Jobs
Keyword & Tag: #OnlinePartTimeJob #WorkFromHome #EarnMoneyOnline #PartTimeJob #jobs #jobalerts #withoutinvestmentjob"
3. Python Applications
Python is used in almost every field of technology:
-
Web Development – Django, Flask, FastAPI.
-
Data Science & Machine Learning – Pandas, NumPy, Scikit-learn, TensorFlow.
-
Artificial Intelligence – Natural Language Processing, Deep Learning.
-
Automation & Scripting – Writing scripts for task automation.
-
Game Development – Pygame.
-
Desktop GUI Applications – Tkinter, PyQt.
-
Cybersecurity & Ethical Hacking – Penetration testing scripts.
-
Internet of Things (IoT) – MicroPython, Raspberry Pi projects.
4. Python Syntax Basics
Here are some simple examples of Python syntax:
Hello World Program
print("Hello, World!")
Variables
x = 10
name = "Python"
print(x, name)
Conditional Statements
num = 5
if num > 0:
print("Positive")
else:
print("Non-positive")
Loops
for i in range(5):
print(i)
Functions
def greet(name):
return "Hello, " + name
print(greet("Alice"))
5. Python Data Types
Python supports different data types:
-
Numeric Types: int, float, complex
-
Sequence Types: list, tuple, range
-
Text Type: str
-
Set Types: set, frozenset
-
Mapping Type: dict
-
Boolean Type: bool
-
Special Type: NoneType
6. Advantages of Python
✔ Easy to learn and use
✔ Large community support
✔ Vast library ecosystem
✔ Portable across systems
✔ Ideal for AI, ML, and Data Science
7. Disadvantages of Python
❌ Slower than compiled languages (like C, C++)
❌ Not ideal for mobile app development
❌ Uses more memory
❌ Weak in multi-threading due to GIL (Global Interpreter Lock)
8. Future of Python
Python continues to grow in popularity due to its role in AI, Data Science, Web Development, and Automation.
-
It is ranked among the top programming languages worldwide.
-
Companies like Google, NASA, YouTube, Instagram, Spotify use Python.
✅ In short: Python is a powerful, easy, and versatile programming language that is shaping the future of technology, AI, and automation.
🐍 Python Multiple Choice Questions with Explanations (100+ MCQs)
1. Python Basics (15 Questions)
Q1. Which of the following is the correct file extension for Python files?
a) .pyth
b) .pt
c) .py
d) .p
✅ Answer: c) .py
👉 Python files are saved with the .py extension.
Q2. Who developed Python programming language?
a) Dennis Ritchie
b) Guido van Rossum
c) James Gosling
d) Bjarne Stroustrup
✅ Answer: b) Guido van Rossum
👉 Python was developed by Guido van Rossum in 1991.
Q3. Which of the following is NOT a feature of Python?
a) High-level language
b) Compiled language
c) Interpreted language
d) Dynamically typed
✅ Answer: b) Compiled language
👉 Python is interpreted, not compiled.
Q4. Which of these symbols is used to start a comment in Python?
a) //
b) #
c) /*
d) <!--
✅ Answer: b) #
👉 Python comments begin with #.
Q5. Which function is used to display output in Python?
a) printf()
b) print()
c) echo()
d) display()
✅ Answer: b) print()
👉 print() is used to display text or values.
Q6. Which of the following is used to take user input in Python 3?
a) scan()
b) input()
c) get()
d) cin>>
✅ Answer: b) input()
👉 input() reads user input as string.
Q7. Python is a:
a) Statically typed language
b) Dynamically typed language
c) Machine-level language
d) Assembly language
✅ Answer: b) Dynamically typed language
👉 No need to declare variable types explicitly.
Q8. Python code is executed by:
a) Compiler
b) Interpreter
c) Assembler
d) None of these
✅ Answer: b) Interpreter
👉 Python runs line by line.
Q9. Which keyword is used to define a block of code in Python?
a) {}
b) begin-end
c) Indentation
d) Brackets
✅ Answer: c) Indentation
👉 Python uses indentation instead of braces.
Q10. Python belongs to which programming paradigm?
a) Procedural
b) Object-Oriented
c) Functional
d) All of the above
✅ Answer: d) All of the above
👉 Python supports multiple paradigms.
Q11. Which version of Python introduced print as a function?
a) Python 2
b) Python 3
c) Python 1
d) None
✅ Answer: b) Python 3
👉 In Python 2, print was a statement.
Q12. What is the extension of a Python compiled file?
a) .exe
b) .pyo
c) .pyc
d) .bin
✅ Answer: c) .pyc
👉 .pyc are compiled Python bytecode files.
Q13. Which of the following is not a Python keyword?
a) pass
b) eval
c) assert
d) main
✅ Answer: d) main
👉 Python has no main keyword.
Q14. Which of the following is correct to declare a variable in Python?
a) int x = 10
b) x = 10
c) var x = 10
d) declare x = 10
✅ Answer: b) x = 10
👉 Python doesn’t need type declaration.
Q15. Which of the following is used to terminate a Python statement?
a) ;
b) .
c) Nothing
d) :
✅ Answer: c) Nothing
👉 Python statements don’t need a terminator.
"This Content Sponsored by SBO Digital Marketing.
Mobile-Based Part-Time Job Opportunity by SBO!
Earn money online by doing simple content publishing and sharing tasks. Here's how:
- Job Type: Mobile-based part-time work
- Work Involves:
- Content publishing
- Content sharing on social media
- Time Required: As little as 1 hour a day
- Earnings: ₹300 or more daily
- Requirements:
- Active Facebook and Instagram account
- Basic knowledge of using mobile and social media
For more details:
WhatsApp your Name and Qualification to 9994104160
a.Online Part Time Jobs from Home
b.Work from Home Jobs Without Investment
c.Freelance Jobs Online for Students
d.Mobile Based Online Jobs
e.Daily Payment Online Jobs
Keyword & Tag: #OnlinePartTimeJob #WorkFromHome #EarnMoneyOnline #PartTimeJob #jobs #jobalerts #withoutinvestmentjob"
2. Python Data Types (10 Questions)
Q16. What is the output of type(3.14)?
a) int
b) float
c) str
d) complex
✅ Answer: b) float
👉 Numbers with decimals are float.
Q17. Which of the following is a mutable data type in Python?
a) tuple
b) list
c) string
d) frozenset
✅ Answer: b) list
👉 Lists are mutable.
Q18. Which of these is immutable?
a) List
b) Tuple
c) Dictionary
d) Set
✅ Answer: b) Tuple
👉 Tuples cannot be changed.
Q19. What will type("123") return?
a) int
b) str
c) float
d) complex
✅ Answer: b) str
👉 Anything inside quotes is a string.
Q20. Which of the following is a complex number in Python?
a) 4+5i
b) 4+5j
c) 4+5k
d) complex(4,5i)
✅ Answer: b) 4+5j
👉 Python uses j for imaginary numbers.
Q21. Which of these is a valid Boolean type?
a) TRUE
b) true
c) True
d) 1
✅ Answer: c) True
👉 Python is case-sensitive; Boolean values are True and False.
Q22. Which of these is NOT a standard Python data type?
a) List
b) Tuple
c) Queue
d) Dictionary
✅ Answer: c) Queue
👉 Queue comes from collections module.
Q23. What is the output of bool(0)?
a) True
b) False
c) 0
d) None
✅ Answer: b) False
👉 Zero is considered False.
Q24. What is the output of type([1,2,3])?
a) list
b) tuple
c) dict
d) set
✅ Answer: a) list
👉 Square brackets define a list.
Q25. Which of these can be used as a key in a dictionary?
a) List
b) Set
c) Tuple
d) Dictionary
✅ Answer: c) Tuple
👉 Keys must be immutable.
3. Python Operators (10 Questions)
Q26. What is the output of 5 // 2?
a) 2.5
b) 3
c) 2
d) 2.0
✅ Answer: c) 2
👉 Floor division removes decimals.
Q27. Which operator is used for exponentiation in Python?
a) ^
b) **
c) //
d) %
✅ **Answer: b) **
👉 Example: 2 ** 3 = 8.
Q28. What is the output of 10 % 3?
a) 1
b) 3
c) 10
d) 0
✅ Answer: a) 1
👉 % gives remainder.
Q29. What does == check in Python?
a) Identity
b) Value equality
c) Assignment
d) Reference
✅ Answer: b) Value equality
👉 Checks if values are equal.
Q30. Which operator checks object identity?
a) is
b) ==
c) :=
d) in
✅ Answer: a) is
👉 is compares object identity.
Q31. Which operator is called the walrus operator?
a) is
b) :=
c) =>
d) ->
✅ Answer: b) :=
👉 Introduced in Python 3.8.
Q32. What is the output of 2**3**2?
a) 64
b) 512
c) 256
d) 8
✅ Answer: b) 512
👉 Right-to-left associativity: 3**2=9, then 2**9=512.
Q33. What is the result of "a" * 3?
a) aaa
b) a3
c) error
d) None
✅ Answer: a) aaa
👉 Strings can be multiplied.
Q34. What is the output of not True?
a) True
b) False
c) 0
d) None
✅ Answer: b) False
Q35. Which operator is used for membership testing?
a) is
b) in
c) ==
d) not
✅ Answer: b) in
👉 Example: 2 in [1,2,3] → True.
4. Python Strings (10 Questions)
Q36. What is the output of "Python".lower()?
a) PYTHON
b) python
c) Python
d) error
✅ Answer: b) python
👉 .lower() converts string to lowercase.
Q37. Which operator is used for string concatenation?
a) *
b) +
c) &
d) %
✅ Answer: b) +
👉 Example: "Hello" + "World" → HelloWorld.
Q38. What is the output of "Hello"[1]?
a) H
b) e
c) l
d) o
✅ Answer: b) e
👉 Indexing starts from 0.
Q39. Strings in Python are:
a) Mutable
b) Immutable
c) Both
d) None
✅ Answer: b) Immutable
👉 You cannot change a string once created.
Q40. What is the output of "abc" * 2?
a) abcabc
b) abc2
c) abcabcabc
d) error
✅ Answer: a) abcabc
👉 String repetition.
Q41. Which method removes whitespace from both ends of a string?
a) strip()
b) trim()
c) remove()
d) clear()
✅ Answer: a) strip()
👉 Removes spaces, tabs, newline.
Q42. What does "Python".find("y") return?
a) 0
b) 1
c) -1
d) error
✅ Answer: b) 1
👉 find() returns the index of first occurrence.
Q43. Which method is used to replace characters in a string?
a) substitute()
b) replace()
c) change()
d) swap()
✅ Answer: b) replace()
Q44. Which of the following creates a multiline string?
a) "Hello\nWorld"
b) '''Hello World'''
c) """Hello World"""
d) Both b and c
✅ Answer: d) Both b and c
👉 Triple quotes are used.
Q45. Which function converts a string into a list of words?
a) split()
b) join()
c) slice()
d) divide()
✅ Answer: a) split()
👉 "a b c".split() → ['a','b','c'].
5. Python Lists & Tuples (10 Questions)
Q46. What is the output of len([1, 2, 3, 4])?
a) 3
b) 4
c) 5
d) Error
✅ Answer: b) 4
Q47. Which of the following is immutable?
a) List
b) Tuple
c) Dictionary
d) Set
✅ Answer: b) Tuple
Q48. Which method adds an item to a list?
a) insert()
b) append()
c) push()
d) add()
✅ Answer: b) append()
Q49. Which method removes the last element from a list?
a) delete()
b) remove()
c) pop()
d) discard()
✅ Answer: c) pop()
Q50. What is the output of [1,2,3] + [4,5]?
a) [1,2,3,4,5]
b) [1,2,3]+[4,5]
c) [1,2,3,[4,5]]
d) error
✅ Answer: a) [1,2,3,4,5]
Q51. Which function sorts a list permanently?
a) sort()
b) sorted()
c) order()
d) arrange()
✅ Answer: a) sort()
Q52. What is the output of (1,2,3) * 2?
a) (1,2,3,1,2,3)
b) (1,2,3,2)
c) (1,2,3,3)
d) error
✅ Answer: a) (1,2,3,1,2,3)
Q53. How to access the last element of a list x?
a) x[-1]
b) x[len(x)]
c) x[last]
d) error
✅ Answer: a) x[-1]
Q54. Which of the following can be nested?
a) List
b) Tuple
c) Both
d) None
✅ Answer: c) Both
Q55. Which function returns the maximum element of a list?
a) max()
b) min()
c) sum()
d) high()
✅ Answer: a) max()
6. Python Dictionaries & Sets (10 Questions)
Q56. What will len({"a": 1, "b": 2, "c": 3}) return?
a) 2
b) 3
c) 6
d) Error
✅ Answer: b) 3
Q57. Which data type is not allowed as a dictionary key?
a) int
b) tuple
c) list
d) string
✅ Answer: c) list
Q58. What is the output of {"a":1,"b":2}["a"]?
a) 1
b) "a"
c) error
d) None
✅ Answer: a) 1
Q59. Which method returns all dictionary keys?
a) keys()
b) values()
c) items()
d) get()
✅ Answer: a) keys()
Q60. Which method removes a specific key from a dictionary?
a) delete()
b) remove()
c) pop()
d) discard()
✅ Answer: c) pop()
Q61. What does set([1,2,2,3]) return?
a) {1,2,2,3}
b) {1,2,3}
c) [1,2,3]
d) error
✅ Answer: b) {1,2,3}
Q62. Which of these creates an empty set?
a) {}
b) set()
c) []
d) None
✅ Answer: b) set()
👉 {} creates an empty dictionary, not a set.
Q63. Which operator is used for set union?
a) |
b) &
c) -
d) ^
✅ Answer: a) |
Q64. Which operator is used for set intersection?
a) |
b) &
c) -
d) ^
✅ Answer: b) &
Q65. Which method clears all items from a dictionary?
a) remove()
b) delete()
c) clear()
d) reset()
✅ Answer: c) clear()
7. Python Conditional Statements & Loops (10 Questions)
Q66. Which keyword is used for decision making in Python?
a) if
b) for
c) loop
d) decide
✅ Answer: a) if
Q67. What is the output of:
for i in range(3):
print(i, end=" ")
a) 1 2 3
b) 0 1 2
c) 0 1 2 3
d) error
✅ Answer: b) 0 1 2
Q68. Which loop executes at least once in Python?
a) for loop
b) while loop
c) do-while loop
d) None
✅ Answer: d) None
👉 Python does not have a do-while.
Q69. What is the output of while False: print("hi")?
a) hi
b) Infinite loop
c) Nothing
d) Error
✅ Answer: c) Nothing
Q70. Which keyword is used to exit a loop prematurely?
a) break
b) exit
c) stop
d) end
✅ Answer: a) break
Q71. Which keyword skips the current iteration in a loop?
a) next
b) pass
c) skip
d) continue
✅ Answer: d) continue
Q72. What is the output of sum(range(5))?
a) 10
b) 15
c) 5
d) 0
✅ Answer: a) 10
👉 0+1+2+3+4 = 10.
Q73. Which keyword is used when no action is required in a loop or function?
a) pass
b) continue
c) break
d) skip
✅ Answer: a) pass
Q74. The range(2,10,2) produces:
a) 2,4,6,8
b) 2,3,4,5,6,7,8,9
c) 2,10
d) error
✅ Answer: a) 2,4,6,8
Q75. What is the output of:
for i in range(3):
pass
print("Done")
a) Done
b) Error
c) Infinite loop
d) Nothing
✅ Answer: a) Done
8. Python Functions (10 Questions)
Q76. Which keyword is used to define a function in Python?
a) fun
b) def
c) function
d) define
✅ Answer: b) def
Q77. What is the output of:
def add(x, y=2):
return x + y
print(add(3))
a) 3
b) 5
c) Error
d) None
✅ Answer: b) 5
Q78. Which keyword is used to return a value from a function?
a) send
b) return
c) break
d) yield
✅ Answer: b) return
Q79. Which of the following defines an anonymous function?
a) def
b) lambda
c) func
d) defanon
✅ Answer: b) lambda
Q80. What is the output of:
f = lambda x: x*2
print(f(3))
a) 3
b) 6
c) Error
d) None
✅ Answer: b) 6
Q81. Which of these is a recursive function?
a) A function calling itself
b) A function calling another function
c) Both
d) None
✅ Answer: a) A function calling itself
Q82. Which keyword is used for variable number of arguments?
a) args
b) *args
c) var
d) multi
✅ *Answer: b) args
Q83. Which keyword is used for variable number of keyword arguments?
a) **kwargs
b) args
c) dictargs
d) multi
✅ **Answer: a) kwargs
Q84. If a function doesn’t return anything, what is returned by default?
a) 0
b) Null
c) None
d) False
✅ Answer: c) None
Q85. Which of the following can be a function name in Python?
a) 123fun
b) fun_123
c) @func
d) fun@
✅ Answer: b) fun_123
9. Python Object-Oriented Programming (10 Questions)
Q86. Which keyword is used to create a class in Python?
a) class
b) struct
c) object
d) def
✅ Answer: a) class
Q87. What is the first parameter of instance methods in Python classes?
a) self
b) this
c) obj
d) cls
✅ Answer: a) self
Q88. Which keyword is used to inherit a class?
a) inherit
b) extends
c) (parent_class)
d) superclass
✅ Answer: c) (parent_class)
Q89. Which method is a constructor in Python classes?
a) init()
b) init()
c) constructor()
d) create()
✅ Answer: b) init()
Q90. What is the output of isinstance(5,int)?
a) True
b) False
c) Error
d) None
✅ Answer: a) True
"This Content Sponsored by SBO Digital Marketing.
Mobile-Based Part-Time Job Opportunity by SBO!
Earn money online by doing simple content publishing and sharing tasks. Here's how:
- Job Type: Mobile-based part-time work
- Work Involves:
- Content publishing
- Content sharing on social media
- Time Required: As little as 1 hour a day
- Earnings: ₹300 or more daily
- Requirements:
- Active Facebook and Instagram account
- Basic knowledge of using mobile and social media
For more details:
WhatsApp your Name and Qualification to 9994104160
a.Online Part Time Jobs from Home
b.Work from Home Jobs Without Investment
c.Freelance Jobs Online for Students
d.Mobile Based Online Jobs
e.Daily Payment Online Jobs
Keyword & Tag: #OnlinePartTimeJob #WorkFromHome #EarnMoneyOnline #PartTimeJob #jobs #jobalerts #withoutinvestmentjob"
Q91. Which method is called when printing an object?
a) print()
b) str()
c) repr()
d) show()
✅ Answer: b) str()
Q92. Which concept allows the same function name with different implementations?
a) Encapsulation
b) Polymorphism
c) Inheritance
d) Abstraction
✅ Answer: b) Polymorphism
Q93. Which method is called when an object is deleted?
a) remove()
b) del()
c) delete()
d) None
✅ Answer: b) del()
Q94. Which access modifier is used to declare private variables?
a) _var
b) __var
c) private var
d) var_private
✅ Answer: b) __var
Q95. Which keyword is used to define a static method?
a) static
b) @staticmethod
c) staticmethod()
d) static_def
✅ Answer: b) @staticmethod
10. Python Modules & Exceptions (10 Questions)
Q96. Which keyword is used to handle exceptions in Python?
a) try-except
b) handle
c) do-catch
d) check
✅ Answer: a) try-except
Q97. Which of the following modules is used for mathematical operations?
a) sys
b) math
c) os
d) random
✅ Answer: b) math
Q98. Which module is used to generate random numbers?
a) random
b) math
c) sys
d) numbers
✅ Answer: a) random
Q99. Which exception is raised when dividing by zero?
a) ArithmeticError
b) ZeroDivisionError
c) ValueError
d) RuntimeError
✅ Answer: b) ZeroDivisionError
Q100. Which function is used to import a module in Python?
a) load()
b) import
c) include()
d) use()
✅ Answer: b) import
Q101. What is the output of import sys; print(sys.version_info[0]) in Python 3?
a) 2
b) 3
c) Error
d) None
✅ Answer: b) 3
Q102. Which module is used to work with operating system functions?
a) os
b) sys
c) subprocess
d) random
✅ Answer: a) os
Q103. Which exception is raised when a list index is out of range?
a) ValueError
b) IndexError
c) KeyError
d) TypeError
✅ Answer: b) IndexError
Q104. Which exception is raised when accessing a missing dictionary key?
a) KeyError
b) ValueError
c) IndexError
d) LookupError
✅ Answer: a) KeyError
Q105. Which function lists all built-in modules?
a) help("modules")
b) listmodules()
c) modules()
d) show()
✅ Answer: a) help("modules")
.jpeg)
.png)

.png)
.png)
No comments:
Post a Comment