0% found this document useful (0 votes)
10 views5 pages

Python Basics for Class X Students

Uploaded by

Prateek
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)
10 views5 pages

Python Basics for Class X Students

Uploaded by

Prateek
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

Page 1 of 5

Python for Class X

❖ Introduction to Python:
Python is a general-Purpose object oriented easy to learn high
level programming language. Guido van Rossum designed
Python.
❖ Why Python for AI:
(i) It is easy to read, write learn and maintain
(ii) Large standard library
(iii) Interactive mode
(iv) Portability and compatibility
(v) Extendable
❖ Python character set:
(i) Digit from 0 to 9
(ii) Alphabets A to Z and a to z
(iii) Special symbol like $, %, &, @ etc.
(iv) Whtie space like spacebar, tab key or enter key
❖ What is a Statement in Python?
Instructions written in a source code and are executed by a
Python interpreter are called statements.
➢ Simple Statement: Statement writing in single line
➢ Multiline Statement: Statement written in multiline using:
(i) Using Parentheses ()
(ii) Using Square Brackets [ ]
(iii) Using the continuation character (\)
➢ Multiple Statement:
More than one statement in one line using semicolon (;).
❖ Comment:
Comments are used to increase the readability of the code.
➢ Single line comment: Starts with # followed by the text.
➢ Multiline comment:
Starts with three single quotes ’’’ or three double quotes ”””
Page 2 of 5

❖ Keywords:
Keywords are words reserved by python have special meaning in
python language.
Example: None, False, class, is, return, True , if, elif, else, for etc.
❖ Identifiers: Variable names are called identifiers.
➢ Rules for identifier:
(i) We can use any alphabet upper or lower case, numbers or
underscore (_).
(ii) It can start with alphabet or an underscore.
(iii) Should not be special character or keywords
(iv) They are case sensitive.
❖ Variable:
Variable are the name given to a memory location to store any
value.
❖ Data Type:
Data types specify the kind of a value a variable can store.
Example:
(i) Numbers: Data with a numeric value.
(ii) Integer: Whole number
(iii) Float: It is a real number with floating point
representation.
(iv) Complex: It is made up of a real number and in imaginary
number.
(v) Null: It is a special datatype with NULL or noting value.
(vi) Boolean: It is a data type with two built in value True or
False.
(vii) Sequence: It is a collection of data store under a common
name.
(viii) String: It is an order sequence of UNICODE character in
single or double quote.
(ix) Lists: It is a sequence of heterogeneous values arrange as
elements and are referred by an index number. It is
mutable and enclosed n square brackets [ ]
List1=[“Jaipur”, “Delhi”, “Agra”]
Page 3 of 5

(x) Tuples: It is a sequence of heterogeneous values arrange


as elements and are referred by an index number. It is
immutable and enclosed in circular brackets ( ).
Mytuple1=(“Jaipur”, “Delhi”, “Agra”)
(xi) Set: A set is a collection of unique elements that is both
mutable and unordered. mySet=(21, 52, 33, 54, 95)

❖ Operators:
Operators are used to perform operator on variables and values.
➢ Arithmetic Operators:
Exponential (**) Multiplication (*) Division (/)
Floor Division (//) Remainder (%) Addition (+)
Subtraction (-)
➢ Relational Operator:
Equal to (==) Not equal to (!=) Greater than (>) Less than (<)
Greater than or equal to (>=) Les than or equal to (<=)
➢ Logical Operator:
(i) AND: Return true if both the operands are true.
(ii) OR: Return true if either the operands is true
(iii) NOT: Return true if the operand is False and vice versa.

➢ Assignment Operator:
+= : Add first and then assigns a new value.
-= : Subtracts first and then assigns a new value.
*= : Multiplies first and then assigns a new value.
//= : Floor Division first and then assigns a new value.
%= : Remainder first and then assigns a new value.
❖ Operator Precedence:
To evaluate an expression with multiple operators we follow and
order of precedence in Python.
❖ Type Conversion:
Type conversion is the process of converting the value of one data
type into another data type. It is of two types:
Page 4 of 5

➢ Implicit type conversion: When the process of converting the


value of one data type into another data type is done
automatically.
➢ Explicit type conversion: Also called type casting because
program does the type conversion exclusively by changing the
data type.
❖ The print( ) Function: print( ) function is used to display output.
❖ The input( ) Function: It is used to take input from the user.
❖ Conditional Statements:
Conditional Statements are used to select the block of statements
to be executed based on the condition.
Example:
1. if (Condition):
2. if (Condition):
:
else
3. if (Condition):
:
elif (Condition)
elif (Condition)
:
else
❖ Looping Statements:
The process of repetition of a set of instructions based on a
criterion is called a loop.
➢ For loop: For loop is used to repeat a set of instructions for a
fix number of time. There are commonly two different ways to
use For Loop:
(i) Using Sequence
(ii) Using Rage( ) Function
➢ The While Loop :
The while Loop is used to repeat a set of instructions as long as
the condition is true.
Page 5 of 5

❖ Array: Arrays are an ordered collection of values of the same data


type that can be arrange in one or more dimensions.

❖ Module and Packages:


A module is a Python file (.py) that contains Python code.

A Package is a collection of related Python module organized with


in directory.

➢ Some commonly used Python package:

(i) NumPy: (Numerical Python) is a library for numerical

computing.

(ii) Pandas: Pandas is a Python Library for data manipulation and

analysis.

(iii) Matplotlib: Matplotlib is a widely used Python library for data

visualization.

(iv) SciPy: It is used for scientific and technical computing.


(v) NLTK: Natural Language Tool Kit is a Python Library designed

for NLP.

(vi) OpenCV: Open-Source Computer Vision Library is a


powerful library for computer vision tasks.

❖ Anaconda:
Anaconda was developed and is maintained by Peter Wang
Oliphant, the founders of Anacaonda, Inc., in 2012.

❖ Jupiter Notebook:
Jupiter Notebook is an open-source web-based application where
a single document contains Python code, output window,

explanations, formulas charts, etc.




Common questions

Powered by AI

In Python, type conversion can be implicit or explicit. Implicit type conversion is performed automatically by Python when it handles different data types, for example, automatically converting an integer to a float during a division operation if one operand is a float. Explicit type conversion, also known as type casting, requires manually changing the data type using functions like int(), float(), or str(). For example, explicitly converting a float to an integer using int().

Module and package systems in Python enhance code organization and reuse by allowing developers to encapsulate functionality within distinct namespaces. A module refers to a single Python file containing definitions and implementations that can be reused easily across programs. Packages allow for a hierarchical directory structure, grouping related modules together, which streamlines large projects by separating functionalities logically. This modular approach fosters reusability, as each module or package can be imported into different scripts, decreasing redundancy and enhancing maintainability .

Python is particularly suitable for Artificial Intelligence applications because it is easy to read, write, learn, and maintain, which accelerates development cycles. Additionally, Python offers a large standard library that provides prebuilt operations to facilitate complex tasks. Its interactive mode allows for dynamic testing of code, enhancing flexibility. Python is also portable and compatible across different platforms, and it is extendable, meaning you can integrate other languages and tools with Python to handle various AI processes efficiently .

'For loops' in Python are used for iterating over a sequence (e.g., list, tuple) or using a range with a fixed number of iterations. Their structured nature makes them ideal for tasks where the number of iterations is predefined. On the other hand, 'while loops' continue execution as long as the condition is true, making them suitable for situations where the number of iterations is conditional-based, not predetermined. 'For loops' provide readability for iterating known collections, while 'while loops' offer flexibility when conditions govern the loop's lifecycle .

Conditional statements enhance Python programs by allowing them to execute different blocks of code based on certain conditions. This adds decision-making capabilities, enabling responses through code branches. For instance, using 'if' allows execution when a condition is true, 'if-else' adds an alternative execution path, and 'if-elif-else' provides additional conditions to check before arriving at an else block. For example, `if score > 50: print('Pass') else: print('Fail')` enables program decisions based on the variable 'score' .

Anaconda enhances Python programming by providing a comprehensive platform for package management and deployment, ideal for data science applications. It simplifies package installation and environment management through the conda tool. Jupyter Notebook complements this by offering an interactive web-based interface, enabling real-time code execution with outputs, explanations, formulas, and visualizations inline. This setup fosters efficient development cycles and debugging, making it popular among data scientists and researchers for its clarity and ability to document steps and results .

Python's built-in functions 'print()' and 'input()' offer crucial advantages in interactive programs by facilitating user interface and interactivity. The 'print()' function is used to display output, essential for providing feedback and information to users or tracking program execution. 'Input()' captures user input, enabling dynamic program responses and tailored user experiences. Together, they allow for seamless human-computer interaction, aiding in developing applications that require user engagement and input-driven logic .

Python is considered extendable because it allows integration with other programming languages, such as C or C++, through various APIs. This provides the advantage of increasing Python's capabilities by leveraging performance-intensive operations that benefit from lower-level languages. This integration boosts execution speed and efficiency, making Python suitable for CPU-intensive tasks. Extensibility implies that developers can incorporate specialized libraries or modules written in other languages, broadening the scope of software applications and optimizing performance-intensive code paths .

Lists in Python are mutable, meaning their content can be changed. This makes them suitable for situations where data needs to be modified. Lists are also versatile and easily traversable. However, this mutability can lead to higher memory usage and inefficient computation if elements frequently change. Tuples, in contrast, are immutable, offering a performance advantage due to fixed storage state, thus saving memory and improving speed. They are beneficial for fixed data collections or constant sequences. The drawback is their inability to change items once created, which can limit flexibility .

Operator precedence in Python dictates the order in which operators are evaluated in expressions. The importance of operator precedence lies in ensuring expressions with multiple operators are evaluated correctly, preventing logical errors. For example, in the expression `3 + 5 * 2`, the multiplication operation (*) precedes the addition due to its higher precedence, resulting in `3 + 10` rather than `(3 + 5) * 2`. Understanding operator precedence ensures the intended calculations are performed without needing parentheses .

You might also like