Uploaded by 22121067 cs

keerthana

advertisement
Introduction
Of Python
Python is a widely used general-purpose, high level programming language. It was
created by Guido van Rossum in 1991 and further developed by the Python Software
Foundation. It was designed with an emphasis on code readability, and its syntax
allows programmers to express their concepts in fewer lines of code. Python is a
programming language that lets you work quickly and integrate systems more
efficiently. There are two major Python versions: Python 2 and Python 3. Both are
quite different.
Day-1: Enrollment and basic instructions
Python is a high-level, general-purpose, and very popular programming language. Python
programming language (latest Python 3) is being used in web development, Machine
Learning applications, along with all cutting-edge technology in Software Industry. Python
language is being used by almost all tech-giant companies like – Google, Amazon,
Facebook, Instagram, Dropbox, Uber… etc.
The biggest strength of Python is huge collection of standard library which can be used
for the following:









Machine Learning
GUI Applications (like Kivy, Tkinter, PyQt etc. )
Web frameworks like Django (used by YouTube, Instagram, Dropbox)
Image processing (like OpenCV, Pillow)
Web scraping (like Scrapy, BeautifulSoup, Selenium)
Test frameworks
Multimedia
Scientific computing
Text processing and many more.
Python Keywords
Keywords in Python are reserved words that can not be used as a
variable name, function name, or any other identifier.
List of Keywords in Python:
Keyword
Descriptio
n
and
It is a
Logical
Operator
as
It is used to
create an
alias name
assert
It is used
for
debugging
break
Break out a
Loop
class
It is used to
define a
class
continu
e
Skip the
next
iteration of
a loop
Keywor
d
Descriptio
n
Keywor
d
Descriptio
n
False
Represents
an
expression
that will
result in
not being
true.
nonloc
al
It is a nonlocal
variable
finally
It is used
with
exceptions
not
It is a
Logical
Operator
for
It is used to
create
Loop
or
It is a
Logical
Operator
pass
pass is
used when
the user
doesn’t
want any
code to
execute
raise
raise is
used to
raise
exceptions
or errors.
return
return is
used to
end the
execution
from
To import
specific
parts of a
module
global
It is used to
declare a
global
variable
if
To create a
Conditional
Statement
Keyword
Descriptio
n
def
It is used to
define the
Function
del
It is used to
delete an
object
elif
Conditional
statements,
same as
else-if
else
It is used in
a
conditional
statement
except
try-except
is used to
handle
these
errors
Keywor
d
Descriptio
n
import
It is used to
import a
module
is
It is used to
test if two
variables
are equal
in
To check if
a value is
present in
a Tuple,
List, etc.
lambda
Used to
create an
anonymous
function
None
It
represents
a null value
Day-2: project analysis
Keywor
d
Descriptio
n
True
Represent
s an
expression
that will
result in
true.
try
Try is used
to handle
errors
while
While
Loop is
used to
execute a
block of
statements
with
with
statement
is used in
exception
handling
yield
yield
keyword is
used to
create a
generator
function
Day-3: module analysis
Day:4 IOT and Embedded system explanation and
Practice with interfacing kit
Day:5 IOT and Embedded system explanation and
Practice with interfacing kit
Day:6 IOT and Embedded system explanation and
Practice with interfacing kit
Day-7: Basic language training and programming
concept preparation
Day-8: Basic language training and programming
concept preparation
Day-9: Basic language training and programming
concept preparation
Day-10: Basic python instruction and
code preparation
An instruction is a command to the computer, a unit of execution. Python
code in this case is a set of instructions. It can be presented as a step-bystep recipe.
Python code is run by an interpreter, a program that executes instructions
strictly, line by line. Like the steps in a recipe, the instructions for the
interpreter are written in order and are separated from each other by
skipping to the next line.
Developers must understand the order of operations in the code, and be
able to mentally divide the program into independent parts that are
convenient for analysis.
Let's look at an example of some code with two instructions. When it's
started, two sentences are displayed sequentially on the screen:
print('Mother of Dragons.')
print('Dracarys!')
# => Mother of Dragons.
# => Dracarys!
We said above that instructions are separated from each other by a line
break. But there is another way; they can be separated by a semicolon — ;:
print('Mother of Dragons.'); print('Drakarys!')
There is no technical difference between the first and second version; the
interpreter will understand the instructions the same way. The only
difference is that it's inconvenient, physically, to read the second version.
It's better to place the instructions under each other. This makes it easier
for colleagues to read your code, maintain it, and make changes.
Day-11: Basic python instruction and code preparation
Basic Python Commands List
1. pip install command
Python was used to create the package manager known as pip. It is used
to organize and install software packages. The Python Package Index is an
online repository of open-source software packages that may be installed
using the pip install command. Open Windows PowerShell before using the
following syntax to install any package to run this command in Windows.
Syntax: pip install package-name
2. type command
To determine an object’s type or class, use the type command.
syntax: type(object)
3. print command
To display a message on the screen or another standard output device,
use the print command. Any object, including a string, can serve as a
message. Any sort of object, including an integer, a string, a list, a tuple,
etc., can be printed with the print command.
syntax: print(object)
4. range command
When n is not included in the generated numbers, the range command is
used to generate a sequence of integers starting by default at 0 and going
up to n. This command is primarily used for loops.
Syntax: range(start, stop, step)



start: is the starting range. Optional; 0 by default.
stop: is the number before which you want to stop. It is a Mandatory.
step: the increment count. Optional; 1 by default.
Learners Also Read: Which Five Python Libraries Are Best For Data
Science?
5. input command
The input command collects user input. Until a value has been input by the
user, the program will not continue. The input function will translate
whatever the user types into a string. You must explicitly convert an integer
if you want to use it as input.
Syntax: input(message)
The message is the text you need to display to the user. (Optional)
6. round command
This command rounds a number to a particular number of decimal digits. In
other words, if a float point value has a certain number of digits after the
decimal, you can use the round command to round off the desired number.
You can specify the desired number of digits after the decimal.
Syntax: round(number, digits)


number: it is the floating-point number.
digits: it is the count of digits you want after the decimal point.
(Optional; By default 0)
7. len command
To determine how many elements are contained in an object, use the len
command or len() function. The len() function returns the number of
characters in the object if it is a string. The number of elements in the list or
tuple, if the object is one of them, will be returned. If you attempt to send an
integer value to len(), it returns an error.
Syntax: len(object)

object: it is the object of which you want to determine the length
(Required)
8. Loop commands
The two basic loop statements in Python are while and for. While the
specified condition is true, a series of statements are carried out using the
while loop command.
Syntax of while loop: while condition:


statements
update iterator
9. for loop command
The for loop command is used to repeatedly run a sequence of statements.
This list, tuple, string, dictionary, etc., can be used as the sequence.
Syntax: for x in sequence:

statements
Python Intermediate Commands
Certainly, here are some intermediate-level Python commands list and
concept that build upon the basics
String Commands
There are many string commands available in the Python programming
language that can be applied to string objects. These commands merely
return a new object; they do not alter the original string object. The
following are some of the crucial string functions:
1. isalnum(): It determines whether a given string contains alphanumeric
characters or not. It gives back a boolean result.
Syntax: stringname.isalnum()
2. capitalize(): If the initial character of the string is lowercase, the
capitalize() method converts it to uppercase. Nothing happens if the initial
character is uppercase, an integer, or any other special character.
Syntax: stringname.capitalize()
3. find(): To find a substring within a string, use the find() command. If the
substring is present, it provides the index of the first instance; if not, it
returns -1.
Syntax: string.find(substring)


string: it is the string in which you want to search.
substring: it is the value that you want to search for.
4. center(): The center command centers a string by using a specified
character as the fill character (by default, a space).
Syntax: string.center(length, character)




string: the string that you want to align in the center.
length: the full length taken by the new string in which both sides will
be filled by character and in the center, we will have the original
string.
character: the character is useful in filling the missing space on
every side.
Default: it is ” ” (space).
Day-12: Basic python instruction and code preparation
Python Program to Add Two Numbers
Example 1: Add Two Numbers
# This program adds two numbers
num1 = 1.5
num2 = 6.3
# Add two numbers
sum = num1 + num2
# Display the sum
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
Run Code
Output
The sum of 1.5 and 6.3 is 7.8
The program below calculates the sum of two numbers entered by the user.
Example 2: Add Two Numbers With User Input
# Store input numbers
num1 = input('Enter first number: ')
num2 = input('Enter second number: ')
# Add two numbers
sum = float(num1) + float(num2)
# Display the sum
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
Run Code
Output
Enter first number: 1.5
Enter second number: 6.3
The sum of 1.5 and 6.3 is 7.8
Day-13: Program practice:
Day-14: Overall revision about the project
Day-15: final completion and certification issue:
Conclusion:
I believe the trial has shown conclusively that it is both possible and
desirable to use Python as the principal teaching language:
1. It is Free (as in both cost and source code).
2. It is trivial to install on a Windows PC allowing students to take their
interest further. For many the hurdle of installing a Pascal or C
compiler on a Windows machine is either too expensive or too
complicated
3. It is a flexible tool that allows both the teaching of traditional
procedural programming and modern OOP
4. It can be used to teach a large number of transferable skills
5. It is a real-world programming language that can be and is used in
academia and the commercial world
6.It appears to be quicker to learn and, in combination with its many
libraries, this offers the possibility of more rapid student development
allowing the course to be made more challenging and varied
and most importantly, its clean syntax offers increased understanding.
Download