Complete Python
Complete Python
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/
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)