0% found this document useful (0 votes)
6 views3 pages

Python Concepts Explanation

The document explains key programming concepts in Python, including global and local variables, inheritance, variable rules, list manipulation methods, and basic input/output operations. It also describes the building blocks of Python, the NumPy package for numerical operations, and the concept of modules. Additionally, it lists and explains various data types in Python.

Uploaded by

Diksha Hirole
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Python Concepts Explanation

The document explains key programming concepts in Python, including global and local variables, inheritance, variable rules, list manipulation methods, and basic input/output operations. It also describes the building blocks of Python, the NumPy package for numerical operations, and the concept of modules. Additionally, it lists and explains various data types in Python.

Uploaded by

Diksha Hirole
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1) Explain Global & Local variable with example

Global variables are defined outside any function and can be accessed anywhere in the code. Local

variables are defined inside a function and can only be accessed within that function.

Example:

x = 10 # Global variable

def func():

y = 5 # Local variable

print("Local:", y)

print("Global:", x)

2) Explain Inheritance with example

Inheritance allows a class (child) to inherit attributes and methods from another class (parent).

Example:

class Animal:

def sound(self):

print("Animal Sound")

class Dog(Animal):

def bark(self):

print("Bark")

d = Dog()

d.sound()

d.bark()

3) Explain variable with their rules and example

Variables store data values. Rules:

- Must start with a letter or underscore

- Cannot start with a number


- Case sensitive

- No special characters (except _)

Example:

name = "Alice"

_age = 25

4) Explain two ways to add object/elements to list

- Using append(): Adds a single element at the end.

Example: mylist.append(4)

- Using insert(): Adds an element at a specified position.

Example: mylist.insert(1, "Hello")

5) WAP to check +ve or -ve no

num = int(input("Enter number: "))

if num > 0:

print("Positive")

elif num < 0:

print("Negative")

else:

print("Zero")

6) Describe building block of python

- Variables and Data Types

- Control Structures (if, loops)

- Functions and Modules

- Classes and Objects

- Exceptions and File Handling


7) Explain Numpy Package

NumPy is a Python library used for numerical operations. It supports large, multi-dimensional arrays

and matrices, and includes mathematical functions.

Example:

import numpy as np

arr = np.array([1, 2, 3])

8) Explain module WAP to define module

A module is a file containing Python code (functions, classes). It can be imported using import.

Example (mymodule.py):

def greet(name):

print("Hello", name)

Usage:

import mymodule

mymodule.greet("John")

9) List Datatypes in python and explain

- int: Integer numbers (e.g., 10)

- float: Decimal numbers (e.g., 10.5)

- str: Text (e.g., "hello")

- list: Ordered, mutable collection (e.g., [1, 2])

- tuple: Ordered, immutable collection (e.g., (1, 2))

- dict: Key-value pairs (e.g., {"a": 1})

- set: Unordered collection of unique items (e.g., {1, 2, 3})

You might also like