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

Complete Python

Python is a high-level, interpreted programming language introduced in 1989, known for its simplicity and versatility. It supports multiple programming paradigms, is easy to learn, and has extensive library support, though it is slower than languages like C. The document covers Python's installation, basic syntax, data types, control structures, functions, and object-oriented programming concepts.

Uploaded by

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

Complete Python

Python is a high-level, interpreted programming language introduced in 1989, known for its simplicity and versatility. It supports multiple programming paradigms, is easy to learn, and has extensive library support, though it is slower than languages like C. The document covers Python's installation, basic syntax, data types, control structures, functions, and object-oriented programming concepts.

Uploaded by

Bhanu B Prakash
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Introduction

to Python
WHAT IS PYTHON?
o Python is the High-Level Programming Language.
o Interpreted.
o Introduced by Gudio Van Rossum at CWI in Netherlands in 1989 December.
o Gen Purpose Programming language and used wide range.
o 1st released version in 1991, and known for simplicity, readability &
versatile.
o From 1991 to 2008 it was developed & yet it was developing and using in
each and every domain and field as well.

WHY PYTHON?
o It works on different platforms.
o Simple syntax like English.
o Runs on Interpreted systems, can be executed soon.
o This means that prototyping can be very quick.
o Python can be treated in a procedural way, an object-oriented way or a functional way.
WHAT CAN PYTHON DO?
o It used to as server to create server side apps.
o Can be used alongside software to create webapp's.
o Handle's bigdata and performs complex maths.

ADVANTAGES OF PYTHON
o Easy to learn and use.
o Improved Productivity (Speed)
o Large Library Support and Portability, Interpreted, OOP's, and more.......

DISADVANTAGES OF PYTHON
o Slower than C.
o Interpreter is slower than Compiler.
o Time Complexity is more comparing to the C & C++.

WORKING OF INTERPRETER
o The Source code of a python programming is converted into byte code then it will executed.
Installations &
Working with
Python
Installations and Hello World!👋🏻
o https://www.python.org/
o https://www.anaconda.com/download
o https://code.visualstudio.com/download
o https://colab.research.google.com/

Print (‘Hello World!’)


Hello World!
Let’s Dive into
Hands-on
Python!
COMMENTS
o To explain Python code.
o To make the code more readable.
o To prevent execution when testing code.
VARIABLES
o A is a container for storing data values.
o Variables are fundamental to programming for 2 reasons:
o 1. Variables Keep Values Accessible. 2. Variables Gives Values Context.
o Variable names can contain letters, numbers & Underscores.
o They cannot contain spaces.
o These names are case sensitive.
o Variables names cannot start with a number.
EXAMPLE OF A VARIABLE: x = "Sri" y = 37
DATA TYPES
o Data types are the classification or categorization of data items.
o Variables can store data of different types & different types can do different things.
o In python the data types are built-in by default.
o The Data Types in Python are:
EXAMPLES OF DATA
1. Text Type:- string ( str )
TYPES:
2. Number Type:- integer ( int ), float, complex X = “Py”
Y = 3.7
3. Sequence Type:- list, tuple, range
Z = 3377
4. Mapping:- dictionary ( dict ) print(type(X))
print(type(Y))
5. Set Types:- set, frozenset
print(type(Z))
6. Boolean:- Boolean ( bool )
7. Binary Type:- bytes, byte array, memoryview
8. None Type:- None Type
STRINGS
o String in python are surrounded by either single or double quotes.

EXAMPLE OF STRING:
x = “Mustang"
print(x)
STRINGS ARE ARRAYS
o Strings in python are arrays of bytes representing unicode characters.
o Python does not have a "character data type", a single character is simply a string with a
length of "l".
o Square brackets can be used to access elements of the string.

EXAMPLE:
a = "Sri"
print(a[1])
SLICING IN STRINGS
o With slicing you can return a range of characters by using the slice syntax.

EXAMPLE:
b = "Data Science!“
print(b[2:5])
ESCAPE SEQUENCE OR CHARACTERS
o To insert characters that are illegal in a string, use an escape character.
o An escape character is backslash "\" followed by the character you want to insert.

EXAMPLE:
txt = "Modi was the best PM in \"India\"
from UP."
LISTS
o Lists are used to store multiple items in a single variable.
o Denoted with Square Brackets "[]"
o These are one of 4 built-in data types in python used to store collections of data, the other 3
are Tuples, Sets, Dictionaries, all with different qualities and usages.

EXAMPLE:
srilist = ["Black", "Yellow", "Blue"]
print("srilist")
TUPLES
o Tuples are used to store multiple items in a single variable.
o Denoted with Parenthesis "()"
o These are one of 4 built-in data types in python used to store collections of data, the other 3
are Lists, Sets, Dictionaries, all with different qualities and usages.
EXAMPLE:
blacklist = ("Black", "Yellow", "Blue")
print(blacklist)
SETS
o Sets are used to store multiple items in a single variable.
o Denoted with Flower Brackets "{}"
o These are one of 4 built-in data types in python used to store collections of data, the other 3
are Lists, Tuples, Dictionaries, all with different qualities and usages.

EXAMPLE:
sirilist = {"BMW", "Ferrari",
"Konigseg"}
print(sirilist)
DICTIONARIES
o Dictionaries are used to store data values in key: value pairs.
o A dictionary is a collection which is ordered*, unchangeable and do not allow duplicates.

EXAMPLE:
thisdict = {
"brand": "Benz",
"model": "AMG",
"year": 2023
}
print(thisdict)
CONDITIONALS AND IF STATEMENTS
If-Else:
o Python supports the usual logical conditions from mathematics:

Equals: a == b
Not Equals: a != b
Less Than: a < b
Less than or equal to: a <= b
Greater than: a > b
Greater than or equal to: a >= b
Else:
o The else keyword catches anything which isn't caught by the preceding conditions.

EXAMPLE:
a = 200
b = 33
if b > a:
print("B is greater than a")
elif a == b:
print("A and B are Equal")
else:
print("A is greater than B")
Short Hand If:
o If you have only one statement to execute, you can put it on some line as as the if students.

Examples:
if a > b: print("a is greater than b")
LOOPS
o Which is meant by infinite.
o Python has 2 primitive loop commands:

1. While
2. For
While Loop:
o With the while loop we can execute a set of statements as long as a condition is true.

EXAMPLE:
i=1
while i < 6:
print(i)
i += 1
Break Statement:
o With the break statement we can stop loop even if the while condition is true.
EXAMPLE:
i=1
while i < 6:
print(i)
if i == 3:
break
i += 1
Continue:
o With the continue statement we can stop the current iteration, and continue with the next.
EXAMPLE:
i=0
while i < 6:
i += 1
if i == 3:
continue
print(i)
Else Statement:
o With the else statement we can run a block of code once when the condition no longer is
true.
EXAMPLE:
i=1
while i < 6:
print(i)
i += 1
else:
print("i is no longer less than 6")
For Loop:
o A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a
string).
o This is less like the for keyword in other programming languages, and works more like an iterator
method as found in other object-orientated programming languages.
o With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.
o The for loop does not require an indexing variable to set beforehand.

EXAMPLE:
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
FUNCTIONS
o A function is a block of code which only runs when it is called.
o You can pass the data known as parameters, into a function.
o A function can return data as a result.
EXAMPLE:
def my_function():
print("Hello from a function")
my_function()
ARGUMENTS IN FUNCTION
o Information can be passed into functions as arguments.
o Arguments are specified after the function name, inside the parentheses you can add as many
parameters as you want.
EXAMPLE:
def my_function(fname):
print(fname + " Refsnes")
my_function("Emil")
my_function("Siri")
my_function(“Gemini")
ARRAYS
o An array is a special variable, which can hold more than one value at a time.
o Arrays are used to store multiple values in one single variable.

EXAMPLE:
cars = ['Mustang', 'Audi', 'Benz’]
print(cars)

CLASSES AND OBJECTS


o Python is an object oriented programming language.
o Almost everything in Python is an object, with its properties and methods.
o A Class is like an object constructor, or a "blueprint" for creating objects.
CLASSES
o A class is a code template for creating objects.
o Objects have member variables and have behaviour associated with them.

EXAMPLE OF CREATING A CLASS: EXAMPLE OF CREATING


OBJECT:
class MyClass: class MyClass:
x=5 x=5
print(MyClass) p1 = MyClass()
OBJECTS print(p1.x)
o Objects are variables that contain data and functions that can be used to manipulate the data.
o The object's data can vary in type (string, integer, etc.)
ANY
DOUBTS🤔

You might also like