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

courseDocs_uqu7onuc

This document provides an introduction to Python programming, highlighting its features such as simplicity, readability, and extensive libraries. It covers essential concepts including tokens, data types, control flow, loops, and the importance of Python libraries for various applications. Additionally, it outlines how to use libraries and their benefits in simplifying coding tasks.

Uploaded by

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

courseDocs_uqu7onuc

This document provides an introduction to Python programming, highlighting its features such as simplicity, readability, and extensive libraries. It covers essential concepts including tokens, data types, control flow, loops, and the importance of Python libraries for various applications. Additionally, it outlines how to use libraries and their benefits in simplifying coding tasks.

Uploaded by

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

MODULE 3: INTRODUCTION TO PYTHON PROGRAMMING

What is Python?

Python is a high-level, interpreted programming language known for its simplicity and
readability. It is widely used for various applications, including web development, data analysis,
artificial intelligence, machine learning, and more.

Features of Python

1.​ Easy to Learn and Use: Python has a simple syntax that resembles natural language,
making it beginner-friendly.

8
2.​ Interpreted: Python code is executed line by line, which helps in debugging.
3.​ Platform Independent: Python can run on different operating systems like Windows,
macOS, and Linux.
4.​ Dynamic Typing: You don’t need to declare variable types; Python assigns them
R
automatically.
5.​ Extensive Libraries: Python has a rich set of libraries, such as NumPy, Pandas, and
Matplotlib, for various purposes.
6.​ Object-Oriented: Python supports object-oriented programming, which helps in creating
reusable code.
7.​ Community Support: Python has a large community for support and resources.
C
Tokens in Python

Tokens are the smallest units in a Python program. They include:

1.​ Keywords: Reserved words like if, else, while, def, etc.
2.​ Identifiers: Names used for variables, functions, or objects.
3.​ Literals: Fixed values like numbers (10, 3.14) or strings ("Hello").
4.​ Operators: Symbols like +, -, *, /, etc.
5.​ Delimiters: Characters like (), {}, [], :, ,, etc.
Data Types in Python

1.​ Numeric Types:


○​ int: Whole numbers (e.g., 10)
○​ float: Decimal numbers (e.g., 3.14)
○​ complex: Complex numbers (e.g., 3+4j)
2.​ Text Type:
○​ str: Sequence of characters (e.g., "Hello")
3.​ Boolean Type:
○​ bool: True or False
4.​ Sequence Types:
○​ list: [1, 2, 3]
○​ tuple: (1, 2, 3)
○​ range: Sequence of numbers
5.​ Mapping Type:

○​ set: {1, 2, 3}

8
○​ dict: Key-value pairs (e.g., {"key": "value"})
6.​ Set Types:

○​ frozenset: Immutable set


7.​ None Type: Represents no value or a null value (e.g., None).
R
Control Flow in Python

Control flow statements decide the direction of execution in a program:

1.if Statement: Executes a block of code if a condition is true.​


C
python​
Copy code​
if x > 10:
print("x is greater than 10")

2.if-else Statement: Executes one block if true, another if false.​


python​
Copy code​
if x > 10:
print("x is greater")
else:
print("x is smaller or equal")
3.elif Statement: Adds multiple conditions.​
python​
Copy code​
if x > 10:
print("x is greater")
elif x == 10:
print("x is equal to 10")
else:
print("x is smaller")

Loops in Python
1.for Loop: Iterates over a sequence (e.g., list, range).​
python​

8
Copy code​
for i in range(5):
print(i)
2.while Loop: Repeats as long as a condition is true.​
python​
Copy code​
x=0
R
while x < 5:
print(x)
x += 1
3.break: Exit the loop prematurely.​
python​
C
Copy code​
for i in range(10):
if i == 5:
break
print(i)
4.continue: Skips the current iteration and moves to the next.​
python​
Copy code​
for i in range(5):
if i == 3:
Continue
print(i)​
Introduction to Python Libraries

Python libraries are collections of pre-defined code that provide specific functionalities to
simplify complex programming tasks. They allow developers to focus on the core logic rather
than writing common functionalities repeatedly.

Importance of Python Libraries

1.​ Ease of Use: Simplifies coding for various applications.


2.​ Time-Saving: Reduces development time by offering ready-made functions.
3.​ Versatility: Covers a broad range of tasks like data analysis, machine learning, web
development, and more.
4.​ Reusability: Functions can be reused across multiple projects.

Features of Python Libraries

●​
●​

8
Pre-written modules for specific tasks.
Easy to import and use in any Python program.
●​
R
Extensive documentation and tutorials available.
●​ Active support from the Python community.

Types of Python Libraries


C
1. Data Manipulation Libraries

●​ NumPy: Handles numerical computations and large arrays.


●​ Pandas: Used for working with structured data like tables and data frames.

2. Data Visualization Libraries

●​ Matplotlib: Creates static, animated, and interactive plots.


●​ Seaborn: Enhances Matplotlib for better statistical graphics.

3. Machine Learning and AI Libraries

●​ Scikit-learn: Provides tools for machine learning and data mining.


●​ TensorFlow: A powerful library for deep learning and neural networks.
4. Web Development Libraries

●​ Django: A high-level framework for building complex web applications.


●​ Flask: A lightweight framework for small to medium web apps.

5. Scientific Computing Libraries

●​ SciPy: Supports advanced computations like calculus and linear algebra.

6. Game Development Libraries

●​ Pygame: Helps create video games with multimedia features.

7. Web Scraping Libraries

●​ BeautifulSoup: Extracts information from web pages.


●​ Scrapy: A framework for large-scale web scraping projects.

8. Utility Libraries

8
●​ OS: Provides functions to interact with the operating system.
●​ Requests: Simplifies sending HTTP requests to websites.
R
How to Use Python Libraries
1.Import the Library​
Use the import keyword to include a library in your program.​
import library_name
C
2.Install Missing Libraries​
If the library is not installed, use pip to install it.​

pip install library_name

3.Use Library Functions​


Call the specific functions you need for your task.​
import numpy as np
arr = np.array([1, 2, 3])
print(arr.mean()) # Calculates the mean of the array

1.​
Benefits of Python Libraries

●​ Reduces Complexity: Built-in functions reduce the need for writing complex code.
●​ Speeds Up Development: Pre-tested functions save debugging time.
●​ Encourages Standardization: Promotes the use of best practices in programming.
●​ Extensive Ecosystem: Thousands of libraries available for every domain.

8
R
C

You might also like