KEMBAR78
Python Unit1 Unit2 Viva QA | PDF | Scope (Computer Science) | Python (Programming Language)
0% found this document useful (0 votes)
15 views3 pages

Python Unit1 Unit2 Viva QA

The document provides an overview of Python basics and data structures, including Jupyter Notebook usage, script execution, comments, variables, data types, and control flow statements. It also covers string manipulation, lists, tuples, dictionaries, and sets, detailing their creation, modification, and key operations. Key concepts such as namespaces, scope, and lambda functions are also explained.
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)
15 views3 pages

Python Unit1 Unit2 Viva QA

The document provides an overview of Python basics and data structures, including Jupyter Notebook usage, script execution, comments, variables, data types, and control flow statements. It also covers string manipulation, lists, tuples, dictionaries, and sets, detailing their creation, modification, and key operations. Key concepts such as namespaces, scope, and lambda functions are also explained.
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

UNIT 1: Basics of Python

Q: What is Jupyter Notebook?

A: Jupyter Notebook is an open-source web application that allows you to create and share

documents containing live code, equations, visualizations, and narrative text.

Q: How do you set the working directory in Jupyter?

A: You can set the working directory using the `%cd` magic command, e.g., `%cd

path_to_directory`.

Q: How to create and save a script file in Jupyter?

A: You can write code in a new notebook and save it using `File > Save and Checkpoint`.

Alternatively, use `.py` extension in a text file.

Q: How is a Python script executed?

A: Scripts can be executed cell by cell in Jupyter or by running `.py` files in terminal using `python

filename.py`.

Q: What are comments in Python?

A: Comments are lines in code that are not executed. Single-line comments start with `#`, multi-line

use triple quotes.

Q: What are variables in Python?

A: Variables are used to store information and do not require explicit declaration of data type.

Q: What are Python's data types?

A: int, float, complex, str, list, tuple, dict, set, bool.

Q: What are Python's arithmetic operators?

A: +, -, *, /, %, //, **

Q: Give examples of built-in functions.

A: `print()`, `len()`, `type()`, `range()`, `input()`

Q: Explain if statement in Python.

A: Used to test a condition and execute block of code if it's true.

Q: Does Python support switch-case?


A: No, Python does not have switch-case. Use if-elif-else instead.

Q: Difference between while and for loop?

A: `while` repeats as long as a condition is true. `for` iterates over a sequence.

Q: What is a namespace in Python?

A: A namespace is a container for names mapping to objects.

Q: Explain scope in Python.

A: Scope determines the visibility of a variable (local, global, nonlocal).

Q: What are local functions?

A: Functions defined inside another function.

Q: Can a Python function return multiple values?

A: Yes, using tuples or lists.

Q: Can functions be objects in Python?

A: Yes, functions are first-class objects and can be assigned to variables.

Q: What is a lambda function?

A: An anonymous, one-liner function defined using the `lambda` keyword.

UNIT 2: Data Structures and Sequences


Q: What is a string in Python?

A: A string is a sequence of characters enclosed in quotes.

Q: How is an array like a string?

A: Strings can be accessed using indexing like arrays.

Q: What is regex in Python?

A: Regex (Regular Expression) is a module for pattern matching using `re`.

Q: How to concatenate strings?

A: Using `+` operator or `join()` method.

Q: How to modify a string?

A: Using slicing, replace(), upper(), lower(), etc.

Q: How to search and sort strings?


A: Use `find()`, `index()`, `sorted()` functions.

Q: How to create a list?

A: Using square brackets: `my_list = [1, 2, 3]`.

Q: How to add/remove elements in list?

A: Use `append()`, `insert()`, `remove()`, `pop()`.

Q: How to slice a list?

A: `list[start:stop:step]` is used for slicing.

Q: How to sort a list?

A: Using `sort()` or `sorted()`.

Q: What is a tuple?

A: An immutable ordered sequence of elements.

Q: Can we add/remove from tuple?

A: No, tuples are immutable.

Q: What are some tuple methods?

A: `count()`, `index()`.

Q: What is a dictionary in Python?

A: Unordered collection of key-value pairs.

Q: How to add/remove items in dictionary?

A: Use `dict[key] = value` to add; `del dict[key]` to remove.

Q: What is hashing in dictionary?

A: Keys are hashed to map to values for fast lookup.

Q: What types can be dictionary keys?

A: Immutable types like strings, numbers, and tuples.

Q: What is a set?

A: Unordered collection of unique elements.

Q: Set operations in Python?

A: Union (`|`), Intersection (`&`), Difference (`-`), Symmetric Difference (`^`).

You might also like