0% found this document useful (0 votes)
78 views5 pages

Practice Sessions

practice sessions for aptitude
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)
78 views5 pages

Practice Sessions

practice sessions for aptitude
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/ 5

Practice Session Test:

1.Define the variable name and variable of type?


Ans: A variable name is an identifier assigned to a storage location in a
computer program. And variable type defines the kind of data that can be
stored in a variable, and it dictates the operations that can be performed on
that data.

2.Define variable with your details?


Ans: Defining variables with my details
name= “Puvvada Hemanjana”
age= 23
is _student = False
is _employee = False
print(f ”Name: {name}”)
print(f ”Age: {age} years”)
print(f ”Is student: {is_ student}”)
print(f ”Is employee: {is _employee}”)

THE OUTPUT OF THE CODE IS:


Name: Puvvada Hemanjana
Age: 23 years
Is student: False
Is employee: False

3.Definition of variable?
Ans: A variable is a named storage location in a computer’s memory that holds
a value. The value stored in a variable can be changed during program
execution.

4.Define variable rules?


Ans: Variable Rules:
Practice Session Test:
• Start with a letter or underscore: e.g., name, _name
• Include letters, digits, underscores: e.g., name1, my _variable
• Case-sensitive
• No spaces or special characters: e.g., first _name

• No reserved keywords: e.g., class (invalid)

5.Difference between variable and identifiers?

Variables:

• Definition: A type of identifier that specifically refers to a storage


location for data.
• Purpose: Store data that can be changed during program execution.
• Examples: ‘age = 23’, ‘name = "Alice"
• Specific identifiers for storing data.

Identifiers:

• Definition: Names for any program element (variables, functions,


classes, etc.).
• Examples: my function, Student Class, MAX_SPEED.
• General names for any code element.

6.A =10, B =10 did id of A and B same or not?

Ans: In Python, when you assign the same small integer value (like 10) to
multiple variables:

python
Copy code
A = 10
B = 10

Both A and B typically share the same memory location of id .This is because
Python optimizes memory usage by reusing memory for small integers and
some other immutable objects.

7.Define a variable with multiples values?

Ans: In programming, you can define a variable to hold multiple values using
different data structures:
Practice Session Test:
1. List: Stores an ordered collection of values.

2.Tuple: Similar to a list but immutable (cannot be changed).

3.Dictionary: Stores key-value pairs for efficie

4.Set: Stores unique elements (unordered).

2. Key Points:

• Lists and tuples are sequences, with tuples being immutable.


• Dictionaries store key-value pairs for efficient lookups.
• Sets store unique elements, useful for operations like finding intersections
or unions.

Usage:

• Choose the appropriate data structure based on the type of data and
operations you need to perform.

This approach allows you to efficiently organize and manipulate data in your
programs.

8.Define variables with same value?

Ans: Assigning the same value to multiple variables simultaneously is a


straightforward operation in programming.

Key Points:

• Efficiency: It simplifies code by reducing redundancy.


• Consistency: Ensures all variables (a, b, c in this case) hold the same
initial value (10).
• Usage: Commonly used for initializing variables or maintaining
uniformity in data across different parts of a program.

9._=10 it is a variable or not, if yes why?

Ans: Yes, _ = 10 is a valid variable assignment in Python.


• Variable Name: _ (underscore) is valid as a variable name in Python.
• Assignment: The statement assigns the value 10 to the variable _.
• Usage: While _ is often used as a placeholder, it still functions as a
regular variable holding the value assigned (10).
Practice Session Test:
10. why we need to use variable?

Ans: Variables are essential in programming because they allow us to store and
manipulate data dynamically throughout our code, enabling us to:

• Manage Data: Store values such as numbers, text, and complex


structures.
• Control Flow: Track and modify program states and conditions.
• Reuse Values: Efficiently use and update data across different parts of
our code.

In essence, variables provide flexibility and efficiency by enabling us to work


with and modify data dynamically within our programs.
Practice Session Test:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy