Python for Beginners pdf free download, dummies, commands, examples, NumPy, SciPy, for Data Scientist, Data Analyst and Data Engineers.

Python for BEGINNERS and DUMMIES

Reusable Define Function with Return


Python 2D Lists and Nested Loops Examples


Python exception handling using
try except with examples


Python For Loop condition with examples


Python while condition with examples


Python if elif else logical condition


Python Tuples vs List


Python Translator with Examples


Python List Functions with Examples


Data Structures and Data Types


Python Exponent Function with examples


Python dictionary with examples


Variables, Expressions & Statements


List of 'Reserved Words' in Python


Boolean Expressions &
Comparison Operators

Python reusable define function and return with examples code


Define Function:


Collection of code which performs a specific task. Definition Function starts with ‘def’.
Function is very commonly used coding technique in Python. In real time scenarios, the python application (or) python data pipeline is developed using one or more python Functions.

Example:

Code:

def name_age(name, age):
===>print("You are " + name + " at age " + age)

name_age("John", "30")


Result:

You are John at age 30

... Click here for full details


Python 2D Lists and Nested Loops with examples


Python 2D Lists and Nested Loops:



Example 1:

number_grid = [
===>[1, 2, 3],
===>[4, 5, 6],
===>[7, 8, 9],
===>[0]
]

for row in number_grid:
===>for col in row:
======>print(col)


Result:

1
2
3
4
5
6
7
8
9
0


... Click here for full details


Python exception handling using try except with examples


Example 1:
try:
===>number = int(input("Enter a number: "))
===>print(number)
except:
===>print("Invalid Number")


First Result:
Enter a number: 9
9

... Click here for full details


Python For Loop condition with examples


Python For Loop Condition Definition:


When there is a need to loop through a set of things such as a list of words (or) the lines in a file. In this case we can construct a definite loop using a for statement.

The key difference between ‘While’ condition and ‘For Loop’:


while statement is an indefinite loop because it simply loops until some condition becomes False.

for loop is looping through a known set of items so it runs through as many iterations as there are items in the set.

Example 1:
friends = ["John", "Kevin", "Karen"]
for friend in friends:
===>print(friend)


Result:
John
Kevin
Karen


... Click here for full details


What is Python While condition explain with examples


Python While Condition Definition:


In while loop the target code execution takes place until the condition used is TRUE.

Example:

i = 1
while i <= 10:
===>print(i)
===>i += 1

print("Loop completed")


... Click here for full details


Python if elif else logical condition with examples


if elif else conditional statement:


Python IF condition helps to develop code based on logical conditions. In general, taking some action based on some condition is ‘true’ or ‘false’ is possible to accomplish by IF ELIF ELSE condition.

Note: Whenever user enters input value, Python converts that in to ‘STRING’ by DEFAULT.

Example: Creating simple calculator using Python ‘IF’ condition

num1 = float(input("Enter first number: "))
op = input("Enter operator: ")
num2 = float(input("Enter second number: "))

if op == '+':
===>print(num1 + num2)
elif op == '-':
===>print(num1 - num2)
elif op == '/':
===>print(num1 / num2)
elif op == '*':
===>print(num1 * num2)
else:
===>print("Invalid Operator")

... Click here for full details


Python Tuples differences vs List


Tuples in Python:


It is a type of data structure. It is a container to store different values. Specially values that are immutable.

Example 1:

Coordinates = (3, 6)


Example 2:

Users = (“hello1”, “simple”, 10, “john”, 50.45)


Example 3 ('List' of 'Tuples'):

Multi_coordinates = [(2, 3), (5, 7), (4,9)]

... Click here for full details


Python Translator with examples


Python Translator:



Option 1:

def translate(phrase):
===>translation = ""
===>for letter in phrase:
======>if letter in "AEIOUaeiou":
=========>translation = translation + "g"
======>else:
=========>translation = translation + letter
===>return translation

print(translate(input("Enter phrase: ")))

Result:

Enter phrase: dog
dgg


... Click here for full details



Python Translator:



Option 1:

def translate(phrase):
===>translation = ""
===>for letter in phrase:
======>if letter in "AEIOUaeiou":
=========>translation = translation + "g"
======>else:
=========>translation = translation + letter
===>return translation

print(translate(input("Enter phrase: ")))

Result:

Enter phrase: dog
dgg


... Click here for full details



Python List Functions:

Examples:

• index
• extend
• append
• insert
• remove
• clear
• pop
• count
• sort
• reverse
• copy

... Click here for full details


Python Data Structures and Data Types

NAME TYPE DESCRIPTIONS
Integers int Whole numbers, such as 1, 2, 10, 20, 30, 35...
Floating point float Numbers with decimal points: 3.5, 2.3, 10.95, 200.75...
Strings str Ordered sequence of characters: "apple", "bike", "house", "32457", hello123"...
Lists list Ordered sequence of objects (these are mutable): ["Apples", 100, "street123", 500.75]
Tuples tup Ordered sequence of objects (these are immutable): ("Oranges", 500, "best123", 700.35)
Dictonaries dict Unordered Key:Value pairs: {"thekey":"thevalue","fruit":"oranges","autos":"cars"}
Sets set Unordered collection of unique objects: {"apple", "mango", "orange"}
Booleans bool Logical value indicating True or False

... Click here for full details


Python Exponent Function Definition:


If you code: print(2**4), this will give the result as: 16.

How to build exponent functions:


Example 1:

def raise_to_power(base_number, power_number):
===>result = 1
===>for index in range(power_number):
======>result = result * base_number
===>return result

print(raise_to_power(2, 4))


Result:

16

... Click here for full details



Python Dictionary Definition:


Dictionary is collection of key and value pairs. These key value pairs need not be in any specific order. But dictionaries mutable and indexed.

Example: Creating Month Conversion using Dictionary concept

monthConversions = {
===>"Jan": "January",
===>"Feb": "February",
===>"Mar": "March",
===>"Apr": "April",
===>"May": "May",
===>"Jun": "June",
===>"Jul": "July",
===>"Aug": "August",
===>"Sep": "September",
===>"Oct": "October",
===>"Nov": "November",
===>"Dec": "December"
}

... Click here for full details



What is variable

It is a place where we can store values. Instead of using the values directly, we can refer the variable name where the actual values are stored.

Example
> x = 2 === > here X is Variable
> name = 'John' === > here NAME is variable


What is Expression

It contains values, variables and operators.

Example
> 10
> x
> y = x + 10

... Click here for full details



Boolean Expression in Python

Boolean Expression helps in confirming True OR False given a comparison.

Example
> 4 == 4
True
> 6 == 2
False

True AND False are not strings. They belong to type bool.
We can validate the type by using the following example code. > type(True)
type 'bool'
> type(False)
type 'bool'

... Click here for full details