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

Jermi Python

Uploaded by

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

Jermi Python

Uploaded by

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

MBARARA UNIVERSITY OF SCIENCE AND TECHNOLOGY

PYTHON ASSIGNMENT.
FACULTY OF COMPUTING AND INFORMATICS
MIREMBE JEREMIAH ARNN 2023/BIT/148/PS

1. What is Python? Describe its key characteristics and popularity.


Python is a high-level, interpreted scripting programming language known for the simplicity and
readability it has.
Characteristics are as follows ;
Python’s syntax is clear and straightforward, making it easy to Learn and Use which further
makes it an excellent choice for beginners.
Python code is an interpreted Language executed line by line, hence simplifying debugging.
Variable types are dynamically Typed and determined at runtime, but not in advance.
Python has a vast of extensive Libraries including standard library and many third-party libraries
for various tasks.
Python is a Cross-Platform making it to work on multiple operating systems, for example
Windows, macOS, and Linux.
Python is popular because it is versatile and used in various fields, such as web development,
data science, artificial intelligence, scientific computing, and automation.

2. What is a script? How does it differ from a program?


A script is a simple program written majorly for automating tasks while a program is more
complex and refers to a complete software application.
3. What are the different data types in Python? Provide examples for each.
Python has many data types;
Numerics;
Integer value. Example: a = 18
Floating values. Example: b = 18.5
Complex number. Example: c = 8 + 3j
Sequence data Types;
String Strc. Example: s = “Hello, Jermi!”
List of some values. Example: l = [1, 2, 3, 4,5,“six”]
Immutable list(Tuple). Example: t = (1, 2, 3,4,5 “six”)
Mapping data Type;
Dictionary of key-data pairs. Example: d = {“name”: “jermi”, “age”: 20}
Set data Types;
Unordered group of unique items. Example: s = {1, 2, 3,4,5}
Immutable values set. Example: fs = frozenset([1, 2, 3,4,5])
Boolean Type;
Boolean data values. Example: flag = False

4. Explain the concept of variables and how they are used in Python.
A variable in Python is a name that is assigned to a value.
Variables are used to store data that can be refered to and manipulated later in the block of code.
A value is assigned to a variable using the operator =.

5. What are operators and their types in Python? Give examples of arithmetic, comparison,
and logical operators.
Operators are special symbols that perform operations on variables. Types of operators are as
follows;
Arithmetic Operators; Do mathematical operations.
+ (Add): 5 + 35
-(Subtract): 5 – 4
*(Multply): 5 * 73
/ (Divide): 5 / 2
% (Modulus): 5 % 2
** (Exponentiation): 5 ** 8
// (Floor Division): 5 // 2
Comparison Operator: Compare value and bring out a boolean result.
== (Equal to): 5 == 5
!= (Not equal to): 5 != 4
 (Greater than): 5 > 4
< (Less than): 5 < 6
≥ (Greater than or equal to): 5 >= 4
≤ (Less than or equal to): 5 < =8
Logical Operators: Do logical operations.
And; True and False
Or; True or False
Not: not False

6. What is the Python interpreter? How does it execute Python code?


Python interpreter is a program that is to read and execute a Python code.
It works in the following steps;
1. The interpreter parses the Python code into a structure that is called an Abstract Syntax
Tree (AST).
2. The AST is compiled to form a bytecode, a lower-level representation of code.
3. The bytecode is then executed by the Python Virtual Machine (PVM).

7. What are comments in Python? How are they used?


Comments are lines that are non-executable in code that provide explanations or notes. They are
ignored by the interpreter during execution . They help to make the code more readable.
They are used in the following ways;
Single-line: Use # symbol.
# My World
Multi-line comments: Use triple quotations‘’’ or “””.
“””
Here is a
Comment
“””

8. Explain the concept of indentation in Python. Why is it important?


Indentation is used to define the structure and the scope of blocks of code in Python, such as
loops and functions. Indentation is used to mark code blocks.

9. What is a Python virtual environment? When would you use it?


A Python virtual environment is an isolated area for Python projects.
Virtual environments prevent collision between project dependencies. It is used;
When working on many projects with different dependencies.
To avoid installation of packages globally and potentially affecting other projects.
To ensure good dependencies across testing, and production environment.

10. What are some common Python development tools and IDEs?
Python development tools and IDEs that are common include:
IDEs;
PyCharm: A full-stocked and featured IDE with advanced debugging, testing, and code
analysing tools.
Visual Studio Code: A lightweight and extensible editor with excellent support for Python.
Spyder: An IDE made for data science containing features for interactive computing.
Jupyter Notebook: An interactive web-based IDE for data analysing and visualization.
Tools;
Pip: A package installer majorly for Python.
Virtualenv: A tool to create multiple isolated Python environments.
Pytest: A framework that is used for writing and running tests.
Black: A code formatter for regular dependable code style.
Flake8: A tool used to check the style and the quality of Python code.

You might also like