0% found this document useful (0 votes)
2 views18 pages

Python Installation and Basics Guide

The document provides a step-by-step guide for installing Python and setting up the Thonny IDE, along with practical exercises on basic programming concepts such as printing, finding prime numbers, Fibonacci series, string slicing, functions and modules, lists, dictionaries, and tuples. Each section includes definitions, examples, and common functions related to the respective topic. The document is authored by Luwai Fakhruddin Fakhri.

Uploaded by

harshalparakhe77
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)
2 views18 pages

Python Installation and Basics Guide

The document provides a step-by-step guide for installing Python and setting up the Thonny IDE, along with practical exercises on basic programming concepts such as printing, finding prime numbers, Fibonacci series, string slicing, functions and modules, lists, dictionaries, and tuples. Each section includes definitions, examples, and common functions related to the respective topic. The document is authored by Luwai Fakhruddin Fakhri.

Uploaded by

harshalparakhe77
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

Practical 1 - Installing python and setting up environment.

Simple
statements like printing the names (“Hello World”), numbers,
mathematical calculations, etc.

❖ Step 1 : Download python


• Go to the official python website : [Link]
• Click “Download python [latest version] “ (e.g., Python 3.12.x).

❖ Step 2 : Run the Installer


When the installer opens:
1. Check the box “Add Python to PATH” — this is very important!
2. Click Install Now.

❖ Step 3 : Install Thonny IDE


• Go to -> [Link]
• Click “Download for Windows”

❖ Step 4 : Install Thonny


• Run the installer and follow the steps.
• It will automatically detect your installed Python version.

❖ Step 5 : Start Using Thonny


Open Thonny → You’ll see a simple interface:
• Top: Write your code.
• Bottom: Python shell for immediate execution.

By – Luwai Fakhruddin Fakhri


❖ Practical

❖ Output

By – Luwai Fakhruddin Fakhri


Practical 2 - Write a program to find all prime numbers within a
given range.

❖ Practical :

❖ Output

By – Luwai Fakhruddin Fakhri


Practical 3 - Write a program to print "n" terms of Fibonacci Series
using Iteration

❖ Practical :

❖ Output

By – Luwai Fakhruddin Fakhri


Practical 4 - Write a program to demonstrate the use of slicing in
string.

❖ What is String ?
In computer programming, a string is a sequence of characters. For example,
"hello" is a string containing a sequence of characters 'h', 'e', '1', '1', and 'o'.

❖ What is String Slicing ?


String slicing is extracting a substring from a string by specifying start and end
indices.

❖ Access String characters.


We can access the characters in a string in three way.
1. Positive Indexing :
Ex.

2. Negative Indexing :
Ex.

3. Slicing String :
Ex.

❖ String Function :

Concept Description Example


upper() Converts all characters in a string to my_string.upper()
uppercase.
lower() Converts all characters in a string to my_string.lower()
lowercase.
Count() Returns the number of occurrences my_string.count("o")
of a specified substring in the string.
length Returns the total number of len(my_string)
characters in the string.

By – Luwai Fakhruddin Fakhri


find() Returns the index of the first my_string.find("Python")
occurrence of a specified substring.
Returns -1 if not found.
replace() Replaces a specified substring with my_string.replace("Python",
another substring. "Java")

❖ Practical :

❖ Output

By – Luwai Fakhruddin Fakhri


Practical 5 - Write a Program related to Functions & Modules.

❖ What is Function ?
• A function is a block of code that performs a specific task.
• Dividing a complex problem into smaller chunks makes our program easy to
understand and reuse.

❖ Type of Function :
There are two types of function in Python programming:
• Standard library functions - These are built-in functions in Python that are
available to use.
• User-defined functions - We can create our own functions based on our
requirements.

❖ Syntax :

• def - keyword used to declare a function


• function_name - any name given to the function
• arguments - any value passed to function
• return (optional) - returns value from a function

❖ What is Modules ?
As our program grows bigger, it may contain many lines of code. Instead of putting
everything in a single file, we can use modules to separate codes in separate files
as per their functionality. This makes our code organized and easier to maintain.
Module is a file that contains code to perform a specific task. A module may
contain variables, functions, classes etc. Let's see an example,

By – Luwai Fakhruddin Fakhri


❖ Practical :

The program name is calculator

❖ Output

By – Luwai Fakhruddin Fakhri


Practical 6 - Write a program to demonstrate the use of list &
related functions.

❖ What is List ?
• Lists are used to store multiple items or values in single variable
• The list is a sequence of data type which is used to store the
collection of data.
• Python list are mutable, ordered, changeable, and allow duplicate values. We
can change their elements after forming.
• List are created using square brackets [ ] and separated by commas.
• List items are indexed, the first item has index [0], the second item has
index [1] etc.

❖ Syntax :

❖ Access list characters.


We can access the characters in a string in three way.
1. Positive Indexing :
Ex.

2. Negative Indexing :
Ex.

3. Slicing String :
Ex.

By – Luwai Fakhruddin Fakhri


❖ List function

Concept Description
append() Add an item to the end of the list
extend() Add item of list and other iterables to the end of the list
insert() Inserts an item at the specified index
remove() Remove item present at the give index
pop() Returns and removes item present at the given index
clear() Removes all items form the list
Index() Returns the index of the first matched item
count() Returns the cout of the specified item in the list
sort() Sort the list in ascending/descending order
reverse() Reverses the item of the list
copy() Returns the shallow copy of the list

By – Luwai Fakhruddin Fakhri


❖ Practical 1 :

❖ Output

By – Luwai Fakhruddin Fakhri


❖ Practical 2 :

By – Luwai Fakhruddin Fakhri


❖ Output

By – Luwai Fakhruddin Fakhri


Practical 7 - Write a program to demonstrate the use of Dictionary
& related functions.

❖ What is Dictionary ?
• Python dictionary is an ordered collection of items, starting from Python 3.7.
• It stores elements in key/value pairs.
• Keys serve as unique identifiers.
• Each key is associated with a specific value.
• Dictionaries are written with curly brackets { }.
• contain keys and values separated by colons :

❖ Common Dictionary Functions/Methods:


Function Description

dict() Creates a new dictionary.


len() Returns the number of items in a dictionary.
keys() Returns all keys in the dictionary.
values() Returns all values in the dictionary.
items() Returns key-value pairs as tuples.
get(key) Returns the value for the specified key.
update() Updates dictionary with specified key-value pairs.
pop(key) Removes item with specified key.
clear() Removes all items from dictionary.

By – Luwai Fakhruddin Fakhri


❖ Practical

❖ Output :

By – Luwai Fakhruddin Fakhri


Practical 8 - Write a program to demonstrate the use of Tuple.

❖ Theory :
A Tuple in Python is an ordered, immutable (unchangeable) collection of elements.
Tuples are used to store multiple items in a single variable and are written using
parentheses ( ).

❖ Key Features of Tuples:

• Tuples are ordered — elements have a defined order.


• Tuples are immutable — cannot be changed after creation.
• Tuples allow duplicate elements.
• Tuples can store different data types.

❖ Common Tuple Functions/Methods:

Function Description

len() Returns the number of elements in a tuple.

count() Returns the number of times a specified value occurs.

index() Returns the index of the first occurrence of a value.

tuple() Converts another data type (like list) into a tuple.

By – Luwai Fakhruddin Fakhri


❖ Practical :

By – Luwai Fakhruddin Fakhri


❖ Output :

By – Luwai Fakhruddin Fakhri

You might also like