Chereads / PYTHON / Chapter 5 - 2.

Chapter 5 - 2.

Features

Applications

Uses

Advantage

Disadvantage

Statements

Identifiers

Loops

Modes

Methods

Functions:

-built in function

+math

+string

Operators

Variable

Modules

List

Set

Tuple

Dictionary

Features :

-

1. Easy To Learn & Use While Coding

2. Extensible Feature

3. Interpreted Language

4. Expressive Language

5. Cross-Platform Portable Language

6. Dynamic Memory Allocation

7. High-Level Interpreted Language

8. Graphical User Interface (GUI) Support:

9. Object-Oriented Language

10. Open Source Programming Language

11. Large Standard Library

12. Easy To Integrate

13. Embeddable

Applications :

1. Web Development

2. Game Development

3. Scientific and Numeric Applications

4. Artificial Intelligence and Machine Learning

5.Desktop GUI

6. Software Development

7. Enterprise-level/Business Applications

8. Education programs and training courses

9. Language Development

10. Operating Systems

11. Web Scraping Applications

12. Image Processing and Graphic Design Applications

Python uses

programming language is used globally to design and build 2D imaging software like Inkscape, GIMP, Paint Shop Pro, and Scribus. Also, Python is used in several 3D animation

Advantages & Disadvantages

😇It is easy to learn and use, and it has an extensive library.

😈Because of its elementary programming, users face difficulty while working with other programming languages.

😇Python increases productivity.

😈Python is a time-consuming language

It has a low execution speed.

😇It is very flexible.

😈There are many issues with the design of the language, which only gets displayed during runtime.

😇It has a very supportive community

😈 It is not suited for memory-intensive programs and mobile applications

different modes of python

-

Interactive Mode

Batch Mode

Script mode

Interactive Mode :

Interactive mode is a command line shell.

-mode allows us to write codes in Python command prompt (>>>)

-mode is used to test the features of the python, or to run a smaller script that may not be reusable.

Batch Mode :

Batch mode is mainly used to develop business applications

Script mode:

script mode programs can be written and stored as separate file with the extension .py and executed.

-Script mode is used to create and edit python source

Modules

are simply files with the ". py" extension containing Python code that can be imported inside another Python Program.

-is a file containing Python definitions and statements. A module can define functions, classes, and variables. A module can also include runnable code

Functions

-A function can be defined as the organized block of reusable code, which can be called whenever required.

-Python allows us to divide a large program into the basic building blocks known as a function

-The function contains the set of programming statements enclosed by {}

-

-A function can be called multiple times to provide reusability and modularity to the Python program.

The Function helps to programmer to break the program into the smaller part.

Python provide us various inbuilt functions like range() or print().

the user can create its functions, which can be called user-defined functions.

There are mainly two types of functions.

User-define functions

- The user-defined functions are those define by the user to perform the specific task.

Built-in functions - The built-in functions are those functions that are pre-defined in Python.

Math's built-in Functions: Here is the list of all the functions and attributes defined

in math module

Function

Description

ceil(x)

Return the Ceiling value. It is the smallest integer, greater or equal

to the number x.

copysign(x, y)

Returns x with the sign of y

cos(x)

Return the cosine of x in radians

exp(x)

Returns e**x

factorial(x)

Returns the factorial of x

floor(x)

Returns the largest integer less than or equal to x

fmod(x, y)

Returns the remainder when x is divided by y

gcd(x, y)

Returns the Greatest Common Divisor of x and y

log(x[, base])

Returns the Log of x, where base is given. The default base is e

log2(x)

Returns the Log of x, where base is 2

log10(x)

Returns the Log of x, where base is 10

pow(x, y)

Return the x to the power y value.

remainder(x, y) Find remainder after dividing x by y.

radians(x)

Convert angle x from degrees to radian

sqrt(x)

Finds the square root of x

sin(x)

Return the sine of x in radians

tan(x)

Return the tangent of x in radians

String build-in functions:

Python includes the following built-in methods to manipulate strings:

Function

Description

capitalize()

Converts the first character to upper case

count()

Returns the number of times a specified value occurs in a string

endswith()

Returns true if the string ends with the specified value

find()

Searches the string for a specified value and returns the position of

where it was found

index()

Searches the string for a specified value and returns the position of

where it was found

isalnum()

Returns True if all characters in the string are alphanumeric

isalpha()

Returns True if all characters in the string are in the alphabet

isdigit()

Returns True if all characters in the string are digits

islower()

Returns True if all characters in the string are lower case

isnumeric()

Returns True if all characters in the string are numeric

isspace()

Returns True if all characters in the string are whitespaces

isupper()

Returns True if all characters in the string are upper case

lower()

Converts a string into lower case

replace()

Returns a string where a specified value is replaced with a specified

value

rfind()

Searches the string for a specified value and returns the last position

of where it was found

rindex()

Searches the string for a specified value and returns the last position

of where it was found

split()

Splits the string at the specified separator, and returns a list

Strip()

Remove spaces at the beginning and at the end of the string:

startswith()

Returns true if the string starts with the specified value

title()

Converts the first character of each word to upper case

translate()

Returns a translated string

upper()

Converts a string into upper case

😇List Tuple Set Dictionary

List is a non-homogeneous data structure that stores the elements in single row and multiple rows and columns

😈Tuple is also a non-homogeneous data structure that stores single row and multiple rows and column

👽Set data structure is also non-homogeneous data structure but stores in single row

👻Dictionary is also a non-homogeneous data structure which stores key value pairs

😇List can be represented by [ ]

😈Tuple can be represented by

( )

👽Set can be represented by { }

👻Dictionary can be represented by { }

😇List allows duplicate elements 😈Tuple allows duplicate elements

👽Set will not allow duplicate elements Set will not allow duplicate elements and

👻dictionary doesn't allow duplicate keys.

😇List can use nested among all 😈Tuple can use nested among all

👽Set can use nested among all 👻Dictionary can use nested among all

😇Example: [1, 2, 3, 4, 5]

😈Example: (1, 2, 3, 4, 5)

👽Example: {1, 2, 3, 4, 5}

👻Example: {1, 2, 3, 4, 5}

😇List can be created using list() function

😈Tuple can be created using tuple() function.

👽Set can be created using set() function

👻Dictionary can be created using dict() function.

😇List is mutable i.e we can make any changes in list.

😈Tuple is immutable i.e we can not make any changes in tuple 👽Set is mutable i.e we can make any changes in set. But elements are not duplicated.

👻Dictionary is mutable. But Keys are not duplicated.

😇List is ordered

😈Tuple is ordered

👽Set is unordered

👻Dictionary is ordered (Python 3.7 and above)

😇Creating an empty list

l=[]

😈Creating an empty Tuple

t=()

👽Creating a set

a=set()

b=set(a)

👻Creating an empty dictionary

d={}

Python operator is a symbol that performs an operation on one or more operands. An operand is a variable or a value on which we perform the operation.

Python Operator falls into 7 categories:

Arithmetic

Relational

Assignment

Logical

Membership

Identity

Bitwise

Arithmetic Operators:

arithmetic operators for different mathematical operations. They are:

+ (Addition)

– (Subtraction)

* (Multiplication)

/ (Division)

** (Exponentiation)

// (Floor division)

% (Modulus)

Relational Operators:

They are also called comparison operators and they compare values.

> (Greater than)

< (Less than)

== (Equal to)

!= (Not equal to)

>= (Greater than or equal to)

<= (Less than or equal to)

Assignment Operators:

They perform an operation and assign a value.

= (Assign)

+= (Add and assign)

-= (Subtract and assign)

*= (Multiply and assign)

/= (Divide and assign)

%= (Modulus and assign)

**= (Exponentiation and assign)

//= (Floor-divide and assign

Logical Operators:

They can combine conditions.

and (Logical and)

or (Logical or)

not (Logical not)

Membership Operators:

check whether a value is in another. Python has 2 membership operators:

in

not in

Identity Operators:

check whether two values are identical. Python has 2 identity operators as well:

is

is not

a. is operator

The is operator returns True if the first value is the same as the second. Otherwise, it returns False.

Bitwise Operators:

They operate on values bit by bit.

& (Bitwise and)

(Bitwise or)

^ (Bitwise xor)

~ (Bitwise 1's complement)

<< (Bitwise left-shift)

>> (Bitwise right-shift)

a. Bitwise and

Loops

allows us to execute a statement or group of statements multiple times.

1 while loop

Repeats a statement or group of statements while a given condition is TRUE. It tests the condition before executing the loop body.

2 for loop

Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.

3 nested loops

You can use one or more loop inside any another while, for or do..while loop.

Built in package & user define package

User defined package: The package we create is called user-defined package.

2)

Built-in package: The already defined package