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

Python

Uploaded by

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

Python

Uploaded by

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

Why Python for AI?

Applications of Python Python is used for a large number


of applications. Some of them are mentioned below:
Run in the Integrated Development Environment (IDE)
IDLE (GUI integrated) is the standard, most popular Python development
environment. IDLE is an acronym of Integrated Development Environment. It lets
one edit, run, browse and debug Python Programs from a single interface. This
environment makes it easy to write programs

Python shell can be used in two ways, viz., interactive mode and script mode
Python Assign Values to Multiple
Variables

Assign Value to Multiple Variables


Python allows you to assign values to multiple variables in one line:
Python Assign Values to Multiple Variables
Assign Value to Multiple Variables

Python allows you to assign values to multiple variables in one line:

Example

x, y, z = "Orange", "Banana", "Cherry"

print(x)

print(y)

print(z)
Python Assign the same value to Multiple Variables in one line

And you can assign the same value to multiple variables in one line:

Example

x = y = z = "Orange"

print(x)

print(y)

print(z)
Working of SEP in Python

Here we will discuss the syntax and some examples to illustrate the working of sep in python:
Syntax
Python
print("something", "something", .., sep = "character to be inserted")
Examples
Python
#code for disabling the soft space feature
print("Coding", "Ninjas", sep = '@')

#for formatting a date


print('25','12','2001', sep='/')

#for formatting the numbers


print(21, 25, sep = '#')
Python Comments

A comment is text that doesn't affect the outcome of a code, it is just a piece of
text to let someone know what you have done in a program or what is being done
in a block of code. In Python, we use the hash (#) symbol to start writing a
comment.
Variables and Datatypes Variables A variable is a named location used to store
data in the memory. It is helpful to think of variables as a container that holds data
which can be changed later throughout programming.
Datatypes Every value in Python has a datatype. Since
everything is an object in Python programming, data types
are actually classes and variables are instance (object) of
these classes.
Python Operators I

Operators are special symbols which represent computation. They are applied on
operand(s), which can be values or variables. Same operators can behave
differently on different data types. Operators when applied on operands form an
expression. Operators are categorized as Arithmetic, Relational, Logical and
Assignment. Value and variables when used with operator are known as
operands.
Types of Error

1. Syntax Errors
A syntax error occurs in Python when the interpreter is unable to parse the code due to the code violating
Python language rules, such as inappropriate indentation, erroneous keyword usage, or incorrect operator
use. Syntax errors prohibit the code from running, and the interpreter displays an error message that specifies
the problem and where it occurred in the code. Here's an example of a Python syntax error:

x = 10

if x == 10

print("x is 10")
2. Runtime Errors

In Python, a runtime error occurs when the program is executing and encounters an unexpected
condition that prevents it from continuing. Runtime errors are also known as exceptions and can
occur for various reasons such as division by zero, attempting to access an index that is out of
range, or calling a function that does not exist.

i) x=5
y = 10
z =x+ w
print(z)

2) x = "10"
y = 5
Z = x + y
print(z)
3. Logical Errors
A logical error occurs in Python when the code runs without any syntax or runtime errors but produces incorrect results due to flawed logic in
the code. These types of errors are often caused by incorrect assumptions, an incomplete understanding of the problem, or the incorrect use
of algorithms or formulas.

Unlike syntax or runtime errors, logical errors can be challenging to detect and fix because the code runs without producing any error
messages. The results may seem correct, but the code might produce incorrect output in certain situations. Here is an example of a logical
error in Python:

n, result = 1

for i in range(1, n):

result = result * i

print(result)
Write the output of the following

j) n = 10
h) i = 0 i) number = 5
g) fruit = "peach" for i in range(n, 0, -1):
while i < 5: while number <= 5:
if i % 2 != 0:
print(i, sep='&', end='&') if number < 5:
for char in fruit: print(i, end='|', sep='--')
i += 1 number = number + 1
else:
print(0) print(number)
print(char,sep='&', end=' ') print(i, end='-', sep='++')

What are augmented assignment operators? How are they useful?

You might also like