Posts

Showing posts from November, 2025

Tkinter in Python

Tkinter in Python  If you want to create GUI (Graphical User Interface) applications in Python, Tkinter is the most popular and beginner-friendly library. It is built into Python, so you don't need to install anything separately. This article explains Tkinter with examples, widgets, layout managers, aand inbuilt functions, making it perfect for students, beginners, and exam aspirants.  What is Tkinter? TKinter is Python's standard GUI package used to create desktop applications. It provides windows, buttons, labels, text fields, dialogues, menus, and more. Tkinter is: Built-in (comes with Python) Easy to use Cross-platform Used to create apps like ✔ Calculator ✔ Notepad ✔ Form applications ✔ Games  Creating Your First Tkinter Window Example 1: Basic Window import tkinter as tk root = tk.Tk() root.title("My First Tkinter App") root.geometry("300x200") root.mainloop() Explanation Tk() → creates main window title() → set...

Set quiz

  MCQ Quiz on Set Data Type in Python Which of the following creates an empty set? {} [] set() empty() Which feature of a set is correct? Ordered collection Unordered unique elements Allows duplicates Supports indexing What will be the output of {1, 2, 2, 3}? {1,2,2,3} {1,2,3} {2,3} Error Which method is used to add an element to a set? add() append() insert() push() Which method removes an element without raising an error? remove() discard() pop() delete() Which operator performs union? & - | ^ Which is NOT a valid set method? update() intersection() difference() slice() What is the output of {1, 2, 3} & {2, 3, 4}? {1,4} {2,3} {1,2,3,4} {3,4} Which operator is used for symmetric difference? | & ^ % What will {1,2,3} - {2,3} return? {1} {2} {3} {1,2,3} Which method clears a set? removeAll() clear() delete() empty() The pop() method remov...

Topic 15: Set in python?

Image
Set Data Type in Python Python provides several built-in data types, and Set is one of the most powerful and useful among them. A set is an unordered collection of unique elements, commonly used for operations like removing duplicates, mathematical set operations, and fast membership testing. You will learn: ✔ What a set is ✔ How to create sets in Python ✔ Important operations on sets ✔ Built-in functions and methods ✔ Practical examples  What is a set in Python? A set in Python is a collection of unordered, unindexed, and unique elements. It is defined using curly braces { } or the set() constructor . Example my_set = {1, 2, 3, 4} print(my_set) # {1, 2, 3, 4} mixed_set = {10, "Python", 3.14} print(mixed_set) # Elements in random order  Key Characteristics of Sets Feature Description Unordered Elements have no fixed position Unique elements Duplicate values are automatically removed Mutable You can add or remove elements No inde...

Preprocessing in Machine Learning?

Image
Machine learning models are only as good as the data they are trained on. Before feeding data into a model, it must be cleaned, transformed, and prepared  a process known as "data preprocessing."  Let’s explore what preprocessing is, why it’s important, and how it’s done with a practical example. What is data preprocessing? Data preprocessing is the process of converting raw data into a clean and usable format for machine learning algorithms. It involves handling missing values, scaling features, encoding categorical variables, and splitting data into training and testing sets. In simple words, preprocessing makes sure that your data is in the right shape and scale for your model to understand. Why is preprocessing important? Without proper preprocessing: Models may produce inaccurate results . Algorithms can become biased due to inconsistent data. Features with large ranges can dominate the training process. Missing or invalid data may cause errors ...

Dictionary Quiz

  Python Dictionary Quiz 🧠 Python Dictionary Data Type – Quiz 1. What is a dictionary in Python? A collection of ordered items A collection of key-value pairs A collection of unique values only 2. Which symbol is used to create a dictionary? [ ] { } ( ) 3. Keys in a Python dictionary must be: Mutable Immutable Duplicated 4. How to access value of key “name” from dictionary d? d.name d[name] d["name"] 5. Which method removes a specific key from a dictionary? remove() discard() pop() 6. Which method returns all keys of a dictionary? get() keys() values() 7. What is the output of len({"a":1, "b":2, "c":3}) ? 3 6 Error 8. Which method is used to co...

Topic 14: Dictionary Data Type in Python

Image
In Python, a dictionary is one of the most powerful and flexible data types. It allows you to store data in key–value pairs , just like a real-world dictionary where words (keys) have meanings (values). Dictionaries are unordered, mutable , and indexed by unique keys , making them ideal for quick lookups and data organization. Syntax of Dictionary # Creating a dictionary my_dict = { "name": "Alice", "age": 25, "city": "Delhi" } Keys : Must be unique and immutable (e.g., strings, numbers, tuples). Values : Can be of any data type (string, list, number, etc.). Creating a Dictionary 1️⃣ Using Curly Braces {} student = {"name": "John", "roll_no": 101, "course": "B.Tech"} 2️⃣ Using dict() Constructor student = dict(name="John", roll_no=101, course="B.Tech") Accessing Dictionary Elements You can access values using their key names . stud...

Tuple Quiz

  Tuple in Python - MCQ Quiz 🟣 Tuple in Python — MCQ Quiz (15) Select one answer per question. Click Submit to see your score. 1. Which Python data type is immutable ? a) list b) tuple c) set d) dict 2. How do you create a single-element tuple containing the string "a"? a) ("a") b) ("a",) c) ["a"] d) (a,) 3. How do you access the first element of a tuple t ? a) t[0] b) t(0) c) t.first() d) t.get(0) 4. Which built-in function converts a list [1,2,3] into a tuple? a) convert() b) to_tuple() c) tuple() d) list() 5. Which operator concatenates two tuples (1,2) and (3,4) ? a) * b) + c) & d) .concat() 6. Which tuple method returns the number of occurrences of a value? a) index() b) find() c) count() d) occurrences() 7. Which of the following ...

Topic 13: Tuple

Image
Tuple in Python? In Python, t uples are one of the most important data types used to store multiple items in a single variable. They are similar to lists, but tuples are immutable   (अपरिवर्तनीय) ,  meaning their elements cannot be changed once assigned. Tuples are often used when you want to store a fixed collection of items that should not be modified during program execution. What is a tuple in Python? A tuple is an ordered , immutable , and heterogeneous  ( भिन्न प्रकार)   collection of elements. You can store different data types such as integers, strings, floats, and even other tuples inside a tuple. Syntax: tuple_name = (element1, element2, element3, ...) Example: my_tuple = (10, 20, 30, "Python", 3.14) print(my_tuple) Output: (10, 20, 30, 'Python', 3.14) Characteristics of Tuples Feature Description Ordered Elements have a defined order and can be accessed by index. Immutable Once created, elements cannot be changed or removed...

Topic 15: File Handling in Python

Image
  File Handling in Python File handling is one of the most important features in Python that allows users to store and access data from files permanently. Unlike variables that store data temporarily in memory, files store data permanently on disk. Python provides built-in functions and methods to create, read, write, and delete files easily. Why File Handling? To store data permanently for future use. To read or process existing data stored in text or binary files. To log information , such as errors or results, during program execution. To exchange data between programs. File Operations in Python Python provides four basic operations for handling files: Operation   Description    Function Open   Opens a file for reading/writing   open() Read   Reads the content of a file   read() , readline() , readlines() Write   Writes data to a file   write() , writelines() Close   Closes an ...

File Handling Quiz

File Handling in Python Quiz 📘 File Handling in Python - MCQ Quiz 1. Which function is used to open a file in Python? file.open() open() open.file() file() 2. What is the default mode of the open() function? w a r x 3. Which method is used to read the entire file content? read() readline() readlines() get() 4. Which file mode is used for appending data? r w a r+ 5. What does the 'b' in mode 'rb' stand for? Binary Buffer Both Byte 6. Which function is used to close a file? end() stop() close() finish() 7. What happens if you open a file in 'w' mode that already exists? File is deleted File content is overwritten File content is appended Error occurs 8. The 'with' statement is used to: Open multiple files Automatical...

Python as an Object-Oriented Programming (OOP) Language

Image
Object-Oriented Programming (OOP) Language Python is not just a powerful scripting language—it is also a fully object-oriented programming (OOP) language. OOP is a programming paradigm that organizes code into objects, which bundle data (attributes) and functions (methods) together. Object-Oriented Programming helps in writing clean, reusable, and modular code, which is easier to maintain and extend. Object Oriented Programming   OOP Concepts in Python Python supports all four major principles of Object-Oriented Programming: Encapsulation Abstraction Inheritance Polymorphism Let’s explore each concept with examples. 1. Encapsulation Encapsulation means wrapping data and methods into a single unit . It restricts direct access to some components, protecting the object’s internal state. Example: class Student: def __init__(self, name, age): self.name = name # public variable self.__age = age # private variable ...

List Quiz

Python List Quiz Python List - 15 MCQ Quiz 1. Which of the following is a valid way to create a list in Python? list = (1,2,3) list = [1,2,3] list = {1,2,3} list = 2. Lists in Python are ____. Immutable Mutable Constant Fixed 3. Which function is used to find the length of a list? count() len() size() length() 4. What is the index of the first element in a Python list? 0 1 -1 None 5. What will be the output of len([10, 20, 30, 40]) ? 3 4 5 Error 6. What method adds an element to the end of a list? append() add() insert() extend() 7. Which method removes the last element from a list? remove() delete() pop() discard() 8. What is the output of [1,2,3] + [4,5] ? [1,2,3,4,5] [5,7,8] [1,2,3][4,5] Error 9. How can you access the last element of a list named my_list ? my_list[-1] my_list[last] my_list[len] my_list[end] 10. What does my_list.clear() do? Deletes the list v...

Topic 12: What is List in python?

Data Type " List " in Python In Python, a List is one of the most commonly used and versatile data types. It allows us to store multiple items in a single variable. Lists are ordered, mutable (changeable), and allow duplicate values  making them perfect for storing collections of data such as numbers, strings , or even other lists. A List in Python is defined as a sequence of items enclosed in square brackets [ ] , separated by commas. Syntax: list_name = [item1, item2, item3, ...] Example: fruits = ["apple", "banana", "cherry"] numbers = [10, 20, 30, 40, 50] mixed = [10, "hello", 3.14, True] Characteristics of Python Lists Property Description Ordered The items have a defined order and can be accessed using an index. Mutable You can change, add, or remove items after creation. Heterogeneous A list can store elements of different data types. Allows Duplicates Lists can contain repeated elements. Dyna...