Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Python Day 3

The document outlines a day-wise schedule for a programming course covering Artificial Intelligence, Machine Learning, and Python, detailing topics for each day. It emphasizes the importance of Python in various fields, its characteristics, applications, and career opportunities, while also providing insights into data types, variables, and basic programming concepts. Additionally, it includes practical examples of Python syntax and operations, such as string manipulation, type conversion, and control structures.

Uploaded by

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

Python Day 3

The document outlines a day-wise schedule for a programming course covering Artificial Intelligence, Machine Learning, and Python, detailing topics for each day. It emphasizes the importance of Python in various fields, its characteristics, applications, and career opportunities, while also providing insights into data types, variables, and basic programming concepts. Additionally, it includes practical examples of Python syntax and operations, such as string manipulation, type conversion, and control structures.

Uploaded by

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

Day wise schedule

Day Subject Topics


Day – 1 Artificial ➢ Introduction to ai
(02-12-2024) Intelligence ➢ Types of ai
➢ Applications of ai
➢ History and evolution of ai
➢ AI Tools and uses

Day – 2 Machine ➢ Introduction to ml


(03-12-2024) Learning ➢ Types of ml
➢ History of ml
➢ Applications of ml
➢ Introduction to python
Day – 3 python ➢ Applications of python
(04-12-2024) ➢ Data types
➢ Conditional statements
➢ Calculations in python
➢ Input & output basics
➢ Relational and logical
operators
➢ Lab practice
Day – 4 Python ➢ Loops
(05-11-2024) ➢ Lists
➢ List methods
➢ Function
➢ Lab parctice
Day – 5 Ai/ml ➢ Oops and exam
(06-11-2024)
PYTHON

Introduction to Python
What is Python?
Python is a very popular general-purpose interpreted, interactive, object-
oriented, and high-level programming language. Python is dynamically-typed and
garbage-collected programming language. It was created by Guido van Rossum
during 1985- 1990. Like Perl, Python source code is also available under the GNU
General Public License (GPL).
Python supports multiple programming paradigms, including Procedural,
Object Oriented and Functional programming language. Python design philosophy
emphasizes code readability with the use of significant indentation.

Python Jobs
Today, Python is very high in demand and all the major companies are
looking for great Python Programmers to develop websites, software components,
and applications or to work with Data Science, AI, and ML technologies. When we
are developing this tutorial in 2023, there is a high shortage of Python
Programmers whereas market demands more number of Python Programmers
due to its application in Machine Learning, Artificial Intelligence etc. Today a
Python Programmer with 3-5 years of experience is asking for around $150,000
annual package and this is the most demanding programming language in
America. Though it can vary depending on the location of the Job. It's impossible
to list all of the companies using Python, to name a few big companies are:

• Google
• Intel
• NASA
• PayPal
• Facebook
• IBM
• Amazon
• Netflix
• Pinterest
• Uber
• Many more...

So, you could be the next potential employee for any of these major companies.
We have developed a great learning material for you to learn Python
Programming which will help you prepare for the technical interviews and
certification exams based on Python. So, start learning Python using this simple
and effective tutorial from anywhere and anytime absolutely at your space

Why Learn Python?


Python is consistently rated as one of the world's most popular
programming languages. Python is fairly easy to learn, so if you are starting to
learn any programming language then Python could be your great choice. Today
various Schools, Colleges and Universities are teaching Python as their primary
programming language. There are many other good reasons which makes Python
as the top choice of any programmer:
• Python is Open Source which means its available free of cost.
• Python is simple and so easy to learn
• Python is versatile and can be used to create many different things.
• Python has powerful development libraries include AI, ML etc.
• Python is much in demand and ensures high salary
Python is a MUST for students and working professionals to become a great
Software Engineer specially when they are working in Web Development Domain.
I will list down some of the key advantages of learning Python:
• Python is Interpreted − Python is processed at runtime by the interpreter.
You do not need to compile your program before executing it. This is similar
to PERL and PHP.
• Python is Interactive − You can actually sit at a Python prompt and
interact with the interpreter directly to write your programs.
• Python is Object-Oriented − Python supports Object-Oriented style or
technique of programming that encapsulates code within objects.
• Python is a Beginner's Language − Python is a great language for the
beginner level programmers and supports the development of a wide range
of applications from simple text processing to WWW browsers to games.

Careers in Python
If you know Python nicely, then you have a great career ahead. Here are
just a few of the career options where Python is a key skill:
• Web designer
• Python developer
• Full-stack developer
• Machine learning engineer
• Data scientist
• Data analyst
• Data engineer
• DevOps engineer
• Software engineer
• Game developer
• Many more other roles
Characteristics of Python
Following are important characteristics of Python Programming –
• It supports functional and structured programming methods
as well as OOP.
• It can be used as a scripting language or can be compiled to
byte-code for building large applications.
• It provides very high-level dynamic data types and supports
dynamic type checking.
• It supports automatic garbage collection.
• It can be easily integrated with C, C++, COM, ActiveX,
CORBA, and Java.
Applications of Python
The latest release of Python is 3.x. As mentioned before, Python is
one of the most widely used language over the web. I'm going to list
few of them here:
• Easy-to-learn − Python has few keywords, simple structure,
and a clearly defined syntax. This allows the student to pick
up the language quickly.
• Easy-to-read − Python code is more clearly defined and
visible to the eyes.
• Easy-to-maintain − Python's source code is fairly easy-to-
maintain.
• A broad standard library − Python's bulk of the library is
very portable and crossplatform compatible on UNIX,
Windows, and Macintosh.
• Interactive Mode − Python has support for an interactive
mode which allows interactive testing and debugging of
snippets of code. Python Tutorial iv
• Portable − Python can run on a wide variety of hardware
platforms and has the same interface on all platforms.
• Extendable − You can add low-level modules to the Python
interpreter. These modules enable programmers to add to or
customize their tools to be more efficient.
• Databases − Python provides interfaces to all major
commercial databases.
• GUI Programming − Python supports GUI applications that
can be created and ported to many system calls, libraries
and windows systems, such as Windows MFC, Macintosh,
and the X Window system of Unix.
• Scalable − Python provides a better structure and support
for large programs than shell scripting.

Variables and Data Types


Variables

Variables are like containers for storing values. Values in the variables can be
changed.
Values

Consider that variables are like containers for storing information. In context of
programming, this information is often referred to as value.
Data Type

In programming languages, every value or data has an associated type to it known


as data type. Some commonly used data types
• String
• Integer
• Float
• Boolean
This data type determines how the value or data can be used in the program. For
example, mathematical operations can be done on Integer and Float types of
data.
String

A String is a stream of characters enclosed within quotes. Stream of Characters


• Capital Letters ( A – Z )
• Small Letters ( a – z )
• Digits ( 0 – 9 )
• Special Characters (~ ! @ # $ % ^ . ?,)
• Space
Some Examples
• "Hello World!"
• "some@example.com"
• "1234"
Integer

All whole numbers (positive, negative and zero) without any fractional part come
under Integers. Examples
...-3, -2, -1, 0, 1, 2, 3,...
Float

Any number with a decimal point


24.3, 345.210, -321.86
Boolean

In a general sense, anything that can take one of two possible values is considered
a Boolean. Examples include the data that can take values like
• True or False
• Yes or No
• 0 or 1
• On or Off, etc.
As per the Python Syntax,
True and False
are considered as Boolean values. Notice that both start with a capital letter.
Assigning Value to Variable

The following is the syntax for assigning an integer value 10 to a variable age
age = 10
Here the equals to = sign is called as Assignment Operator as it is used to assign
values to variables.
Expression

An expression is a valid combination of values, variables and operators.


Examples a * b a + 2 5 * 2 + 3 * 4
BODMAS The standard order of evaluating an expression
• Brackets (B)
• Orders (O)
• Division (D)
• Multiplication (M)
• Addition (A)
• Subtraction (S)
Eg: print(10 / 2 + 3)
print(10 / (2 + 3))

Working with Strings

String Concatenation
Joining strings together is called string concatenation.
Eg:
a = "Hello" + " " + "World"
print(a)
output: Hello World

String Repetition

* operator is used for repeating strings any number of times as required.


Eg:
a = "*" * 10
print(a)
output: **********
eg:
s = "Python"
s = ("* " * 3) + s + (" *" * 3)
print(s)
output: * * * Python * * *

Length of String

len()
returns the number of characters in a given string.
Eg:
username = input()
length = len(username)
print(length)
Input
Ravi
Output
4

Take Input From User

• input() allows flexibility to take the input from the user.


• input() reads a line of input as a string.
Example - 1:
username = input()
print(username)
Input
Ajay
Output
Ajay
Example - 2:
username = input()
age = input()
print(username + " is " + age + " years old")
Input
Ravi
10
Output
Ravi is 10 years

String Slicing

Obtaining a part of a string is called string slicing.


variable_name[start_index:end_index]
• Start from the start_index and stops at end_index
• end_index is not included in the slice.
message = "Hi Ravi"
part = message[3:7]
print(part)
Output
Ravi
Slicing to End

If end index is not specified, slicing stops at the end of the string.
message = "Hi Ravi"
part = message[3:]
print(part)
Output
Ravi

Slicing from Start

If start index is not specified, slicing starts from the index 0.


message = "Hi Ravi"
part = message[:2]
print(part)
Output
Hi

Checking Data Type

Check the datatype of the variable or value using type()

Printing Data Type

print(type(10))
print(type(4.2))
print(type("Hi"))
Output
<class 'int'>
<class 'float'>
<class 'str'>

Type Conversion

Converting the value of one data type to another data type is called Type
Conversion or Type Casting. We can convert
• String to Integer
• Integer to Float
• Float to String and so on.
String to Integer int() converts valid data of any type to integer
a = "5"
a = int(a)
print(type(a))
print(a)
Output
<class 'int'>

Invalid Integer Conversion


a = "Five"
a = int(a)
print(type(a))
Output
ValueError:
invalid literal for int() with base 10: 'Five'
a = "5.0"
a = int(a)
print(type(a))
Output
invalid literal for int() with base 10: '5.0'

Adding Two Numbers


a = input()
a = int(a)
b = input()
b = int(b)
result = a + b
print(result)
Input
2
3
Output
5

Integer to String str() converts data of any type to a string.


a = input()
a = int(a)
b = input()
b = int(b)
result = a + b
print("Sum: " + str(result))
Input
2
3
Output
Sum: 5

Summary

1. int() = Converts to integer data type


2. float() = Converts to float data type
3. str() = Converts to string data type
4. bool() = Converts to boolean data type

Relational Operators

Relational Operators are used to compare values.


Gives True or False as the result of a comparison.
These are different relational operators

Operator Name

> Is greater than

< Is less than

== Is equal to

<= Is less than or equal to

>= Is greater than or equal to

!= Is not equal to
print(5 < 10)
print(2 > 1)
Output
True
True

Comparing Numbers

print(2 <= 3)
print(2.53 >= 2.55)
Output
True
False

Comparing Integers and Floats

print(12 == 12.0)
print(12 == 12.1)
Output
True
False
Comparing Strings

print("ABC" == "ABC")
print("CBA" != "ABC")
Output
True
True
Case Sensitive

print("ABC" == "abc")
Output
False
Python is case sensitive. It means X (Capital letter) and x (small letter) are not the
same in Python.

Strings and Equality Operator

print(True == "True")
print(123 == "123")
print(1.1 == "1.1")
Output
False
False
False

Logical Operators

Logical operators are used to performing logical operations on Boolean values.


Gives True or False as a result.
Name Code Output

and print((5 < 10) and (1 < 2)) True

or print((5 < 10) or (2 < 2)) True

not print(not (2 < 3)) False

Logical Operators Truth Table:


A B A and B

True True True

True False False

False False False

False True False

A B A or B

True True True

True False True

False False False

False True True

A Not A

True False

False True

Conditional Statements

Block of Code

A sequence of instructions are called block of code.


Python executes code in a sequence.
Condition

An expression that results in either True or False


Examples
i. 2 < 3
ii. a == b
iii. True
Conditional Statement

Conditional Statement allows you to execute a block of code only when a specific
condition is True

Conditional Block

Block of code which executes only if a condition is True is called Conditional Block.

Indentation
• Space(s) in front of the conditional block is called indentation.
• Indentation(spacing) is used to identify Conditional Block.
• Standard practice is to use four spaces for indentation.
If - Else Syntax

When If - Else conditional statement is used, Else block of code executes if the
condition is False

Using If-Else

a = int(input())
if a > 0:
print("Positive")
else:
print("Not Positive")
print("End")
Input
2
Output
Positive
End
Loops

So far we have seen that Python executes code in a sequence and each block of
code is executed once.
Loops allow us to execute a block of code several times.

While Loop

Allows us to execute a block of code several times as long as the condition is True
.

While Loop Example

The following code snippet prints the next three consecutive numbers after a
given number.
a = int(input())
counter = 0
while counter < 3:
a=a+1
print(a)
counter = counter + 1
Input
4
Output
5
6
7

For Loop

For statement iterates over each item of a sequence.

Examples of sequences:
• Sequence of Characters (string)
• Sequence of numbers, etc.
Eg:
word = "Python"
for each_char in word:
print(each_char)
Output
P
y
t
h
o
n
Range

Generates a sequence of integers starting from 0. Syntax:


range(n)
Stops before n (n is not included).
Eg:
For number in range(3):
print(number)
PYTHON
Output
0
1
2
Range with Start and End

Generates a sequence of numbers starting from start


Syntax:
range(start, end)
Stops before end (end is not included).
for number in range(5, 8):
print(number)
Output
5
6
7

You might also like