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

Q and A

PYTHON PGRRCDE UNIT 1

Uploaded by

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

Q and A

PYTHON PGRRCDE UNIT 1

Uploaded by

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

1.

Discuss the features of Python:

Python is a versatile and powerful programming language known for its simplicity, readability, and
extensive libraries. Some key features include:

 Simplicity: Python's syntax is easy to read and write, making it an excellent choice
for beginners.

 Readability: Code is well-structured, with indentation being a key part of Python,


enhancing code readability.

 Versatility: Python is used in various domains, including web development, data


science, machine learning, and automation.

 Standard Library: Python has a vast standard library that simplifies complex tasks.

 Interpreted Language: Python code is executed line by line, which aids in debugging.

 Open Source: Python is an open-source language, supported by a thriving


community.

 Dynamic Typing: Python allows dynamic typing, where variables are assigned data
types at runtime.

 Cross-Platform: Python is compatible with multiple operating systems.

2. Describe the variables in Python:

 What Are Variables? Variables are used to store data values. In Python, variables are
created when you assign a value to them.

 Variable Naming: Variable names should start with a letter or an underscore,


followed by letters, numbers, or underscores. They are case-sensitive.

 Variable Assignment: Assigning a value to a variable can be done using the =


operator.

 Data Types: Python supports various data types like int, float, string, and more.

 Variable Scope: Variables can have local or global scope, affecting their accessibility.

 Variable Reassignment: You can change the value of a variable by reassigning it.

3. Explain the idea of reference semantics:

In Python, variables are references to objects. This means when you assign a variable to a value, it's
actually a reference to an object in memory. Reference semantics affect mutable and immutable
objects:

 Mutable Objects: Changes to a mutable object are reflected in all references to that
object. E.g., lists and dictionaries.

 Immutable Objects: When you change the value of an immutable object, a new
object is created. E.g., integers, strings, and tuples.

This concept is essential for understanding how data is shared and modified in Python.

4. List out the standard data types of Python:


Python has several standard data types, including:

 int (integers)

 float (floating-point numbers)

 str (strings)

 list (lists)

 tuple (tuples)

 dict (dictionaries)

 set (sets)

 bool (booleans)

5. Discuss the number data type:

The number data type in Python includes integers (int) and floating-point numbers (float). Integers
are whole numbers, and floats are numbers with decimal points. Python allows arithmetic
operations on numbers.

6. Give a few examples of numeric values:

 Integer: 42

 Float: 3.14

 Arithmetic operations: 2 + 3, 4.5 * 2

7. Discuss the operations performed on sequences:

Sequences in Python include lists, tuples, and strings. Common operations on sequences include
indexing, slicing, concatenation, repetition, length measurement, membership testing, and iteration.

8. Differentiate between lists and tuples:

 Lists: Lists are mutable, denoted by square brackets ([]), and can be modified after
creation.

 Tuples: Tuples are immutable, denoted by parentheses (()), and cannot be changed
once defined.

9. Describe the functions of the string data type:

The string data type (str) is used to represent text in Python. String functions include operations for
string manipulation like concatenation, slicing, formatting, and searching.

10. Illustrate examples of data type conversions:

Data type conversions are crucial when working with different data types. Examples include:

 Converting a string to an integer: int("42")

 Converting an integer to a string: str(123)

11. Define what an expression is:


An expression is a combination of values, variables, operators, and function calls that results in a
single value. Expressions are evaluated to produce a result.

12. What is a Python statement:

A statement is a line of code that performs a specific action. Python statements are often used to
modify variables, call functions, or control the flow of a program.

13. Differentiate between a statement and an expression:

 Expression: An expression produces a value and can be part of a statement. For


example, 2 + 3 is an expression that results in the value 5.

 Statement: A statement is a full line of code that performs an action. For example,
an assignment statement like x = 5 assigns the value 5 to the variable x.

14. With an example program, explain arithmetic operators:

a = 10 b = 5 addition = a + b subtraction = a - b multiplication = a * b division = a / b remainder = a %


b power = a ** b floor_division = a // b

15. Give the uses of comparison operators:

Comparison operators are used to compare values and produce boolean results. They are used in
conditional statements and loops to make decisions based on comparisons.

16. Discuss the working of membership operators:

Membership operators (in and not in) are used to check if a value exists within a sequence (e.g., a
string, list, or tuple). They return True or False based on the presence of the value in the sequence.

17. Describe the identity operators:

Identity operators (is and is not) are used to compare the memory location of two objects. They
determine if two variables refer to the same object in memory.

18. Explain the precedence and associativity of operators:

 Precedence: Operator precedence determines the order in which operations are


performed. Operators with higher precedence are evaluated first.

 Associativity: Associativity defines the order of evaluation when operators have the
same precedence. It can be left-to-right or right-to-left.

Understanding these principles helps ensure that expressions are evaluated correctly. For example, in
5 + 3 * 2, multiplication has higher precedence, so it's evaluated first, resulting in 11

You might also like