0% found this document useful (0 votes)
2 views

Python QA Basics

The document outlines basic Python concepts, including standard data types such as numeric, sequence, mapping, set, boolean, binary, and None type. It provides syntax for if...elif...else conditionals, explains the range() function, and discusses when to use dictionaries over lists. Additionally, it distinguishes between errors and exceptions, noting that errors are serious and unrecoverable, while exceptions can be handled during runtime.

Uploaded by

oneplus97891
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Python QA Basics

The document outlines basic Python concepts, including standard data types such as numeric, sequence, mapping, set, boolean, binary, and None type. It provides syntax for if...elif...else conditionals, explains the range() function, and discusses when to use dictionaries over lists. Additionally, it distinguishes between errors and exceptions, noting that errors are serious and unrecoverable, while exceptions can be handled during runtime.

Uploaded by

oneplus97891
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Basics - Q&A

1. List the data types in Python.

Python has the following standard data types:

- Numeric: int, float, complex

- Sequence: str, list, tuple, range

- Mapping: dict

- Set: set, frozenset

- Boolean: bool

- Binary: bytes, bytearray, memoryview

- None type: NoneType

2. Write the syntax for if...elif...else conditionals.

if condition1:

# code block

elif condition2:

# code block

else:

# code block

3. Explain range() function with its syntax.

The range() function generates a sequence of numbers.

Syntax:

range(start, stop, step)

- start: (optional) starting value (default is 0)

- stop: end value (not inclusive)

- step: (optional) difference between each number (default is 1)

Example: range(1, 10, 2) generates: 1, 3, 5, 7, 9


4. When is a dictionary used instead of a list?

A dictionary is used when you want to associate keys with values and need fast lookups based on

custom keys.

Use a dictionary when:

- You need to store data with a unique identifier (like a name, ID).

- Fast retrieval by key is required.

- Order doesn't matter (in older Python versions).

5. Describe the distinction between Errors and Exceptions.

- Errors: Serious problems that a program should not try to catch (e.g., syntax errors).

- Exceptions: Issues that can be caught and handled during runtime (e.g., ZeroDivisionError,

FileNotFoundError).

Errors are usually unrecoverable, while exceptions can be managed using try-except blocks.

You might also like