Basics of Python
Basics of Python
1
WHAT IS PYTHON ?
https://www.careerera.com 2
WHY PYTHON IS WIDELY USE?
• The python language is one of the most accessible programming
languages.
• Due to its ease of learning and usage, python codes can be easily
written and executed much faster than other programming
languages.
• Python works on different platforms (Windows, Mac, Linux etc).
• Python has a simple syntax.
• Python is easy to code.
• Python runs on an interpreter system, meaning that code can be
executed as soon as it is written.
• Python is a object Oriented Programming Language
3
WHAT ARE THE BASIC PROGRAMMING SYNTAX ?
4
HOW TO PERFORME HELLO WORLD PROGRAM IN PYTHON?
• For example :
https://www.careerera.com 5
WHAT ARE VARIABLES ?
• Variables are reserved memory locations to store values. This
means that when you create a variable you reserve some
space in memory.
• Based on the data type of a variable, the interpreter allocates
memory and decides what can be stored in the reserved
memory.
• Therefore, by assigning different data types to variables, you
can store integers, decimals or characters in these variables.
6
WHAT ARE OPERATORS ?
7
HOW MANY TYPES OF OPERATORS ?
There are 7 arithmetic operators in Python :
• Arithmetic operators
• Assignment operators
• Comparison operators
• Logical operators
• Identity operators
• Membership operators
• Bitwise operators
https://www.careerera.com 8
HOW MANY TYPES OF ARITHMETIC OPERATORS ?
There are 7 arithmetic operators in Python :
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Modulus
6. Exponentiation
7. Floor division
9
HOW ADDITION OPERATOR IS USED ?
10
HOW SUBTRACTION OPERATOR IS USED ?
11
HOW MULTIPLICATION OPERATOR IS USED?
12
HOW DIVISION OPERATOR IS USED ?
4. Division Operator : In Python, / is the division operator. It
is used to find the quotient when first operand is divided by
the second.
Example :
13
HOW MODULUS OPERATOR IS USED ?
5. Modulus Operator : In Python, % is the
modulus operator. It is used to find the
remainder when first operand is divided by the
second.
Example :
14
WHAT IS EXPONENTIATION OPERATOR ?
15
HOW ARE USED FLOOR DIVISION ?
7. Floor division : In Python, // is used to conduct the floor
division. It is used to find the floor of the quotient when first
operand is divided by the second.
Example :
16
WHAT ARE LOGICAL OPERATOR ?
• Logical Operators in Python are used to perform logical
operations on the values of variables.
• The value is either true or false. We can figure out the conditions
by the result of the truth values.
• There are mainly three types of logical operators in
python : logical AND, logical OR and logical NOT.
17
HOW MANY TYPES OF LOGICAL OPERATORS?
not Reverse the result, returns not(x < 5 and x < 10)
False if the result is true
18
WHAT ARE DATA TYPES - NUMBERS ?
• Number data types store numeric values. They are immutable data
types, means that changing the value of a number data type results
in a newly allocated object.
• Number objects are created when you assign a value to them.
For example :−
var1 = 10
var2 = 30
19
WHAT IS BOOLEAN ?
20
WHAT ARE STRINGS DATATYPES ?
For Example:-
value = “Careerera”
21
WHAT IS CONCATENATION IN PYTHON ?
22
WHAT ARE SUBSET IN PYTHON ?
Subset - A set of which all the elements are contained in
another set.
• The issubset() method returns True if all elements of a
set are present in another set (passed as an
argument).
• If not, it returns False.
• For Example :-
23
WHAT IS POSITION ?
For Example:
Syntax:
list.index(element, start, end)
24
WHAT ARE INTEGRATED DEVELOPMENT ENVIRONMENT(IDE) FOR PYTHON ?
25
WHAT ARE DATA STRUCTURES ?
27
WHAT IS SYNTAX AND EXAMPLES OF LIST ?
Syntax:
Li=[] # empty list
Li1=[1,2,34,5] # list containing element’s
List Example:
28
WHAT IS TUPLE IN PYTHON ?
29
WHAT IS SYNTAX AND EXAMPLE OF TUPLES ?
• Syntax:
• a=(1,5,8,9)
• B=(True , False , True)
• Tuple Example:
30
WHAT IS SETS IN PYTHON ?
31
WHAT IS SYNTAX AND EXAMPLE OF SETS ?
Syntax:
• a={“Apple” , “Orange” , “Banana” }
Set Example:
32
WHAT IS DICTIONARIES IN PYTHON ?
33
WHAT IS SYNTAX AND EXAMPLE OF DICTIONARIES ?
Syntax:
• a={“keys “ :”values”, “keys “ :”values”}
Dictionary Example:
34
WHAT ARE CONDITIONAL STATEMENT ?
https://www.careerera.com 35
HOW THE IF (CONDITION) FLOW CHART LOOKS LIKE?
https://www.careerera.com 36
HOW TO USE IF STATEMENT ?
• If statement is most usually used as a conditional statement.
37
HOW TO USE IF ELSE STATEMENT IN PYTHON ?
https://www.careerera.com 38
HOW TO USE ELIF STATEMENT ?
39
WHAT ARE NESTED CONDITION ?
40
WHAT ARE LOOPS IN PYTHON ?
• A loop is used for iterating over a sequence (that is either a list, a
tuple, a dictionary, a set, or a string).
• With the for loop we can execute a set of statements, once for each
item in a list, tuple, set etc.
For Example:
41
WHAT IS FOR LOOP IN PYTHON ?
• A for loop is used for iterating over a sequence (that is
either a list, a tuple, a dictionary, a set, or a string).
• With the for loop we can execute a set of statements,
once for each item in a list, tuple, set etc.
For Example:
42
HOW TO WRITE PROGRAMS FOR FOR LOOP & WHILE LOOP IN PYTHON?
• Loop program:
43
HOW WHILE LOOP IS USED IN PYTHON ?
• With the while loop we can execute a set of statements
as long as a condition is true.
For Example:
44
WHAT ARE THE BASIC CONCEPTS OF OBJECT-ORIENTED
PROGRAMMING IN PYTHON?
45
WHAT ARE FUNCTIONS ?
46
HOW TO USE LENGTH FUNCTION ?
Length : len() function is an inbuilt function in Python
programming language that returns the length of the
string.
Syntax:
len(string)
For Example:
47
WHAT IS FILTER FUNCTION ?
• The filter() method constructs an iterator from elements of an
iterable for which a function returns true.
• Python's filter() is a built-in function.
• The filter function takes in two arguments
SYNTAX:
filter(function, iterable)
48
WHAT IS LAMBDA FUNCTION?
• A lambda function is a small, anonymous function
that take any number of arguments but only have one
expression.
• We create them with the lambda keyword instead of the
traditional def keyword.
https://www.careerera.com 49
WHAT IS MAP FUNCTION ?
• Map is a function that takes as an input a collection
Example:
• a list [‘BBA’,’MBA’,’BCA’], and a function e.g. upper().
• Then it will move every element of the collection through this
function and produce a new collection with the same count of
elements.
SYNTAX:
map(function, iterables)
https://www.careerera.com 50
WHAT IS REDUCE FUNCTION ?
51
WHAT KIND OF BUILT IN FUNCTION IN PYTHON?
• The min() function returns the item with the lowest value,
or the item with the lowest value in an iterable.
For Example:
https://www.careerera.com 52
WHAT IS MAX FUNCTION IN PYTHON ?
53
HOW SORT FUNCTION IS USED IN PYTHON ?
54
WHAT IS USER DEFINED FUNCTIONS?
• A user-defined function (UDF) is a function provided by the
user of a program or environment.
For Example:
Here sum is the user define function.
https://www.careerera.com 55
WHAT IS CLASS ?
WHAT IS OBJECT ?
58
HOW MANY TYPES OF INHERITANCE IN PYTHON?
59
Class Definition Syntax: class ClassName: # Statement-1 . . . # Statement-N
WHAT IS ENCAPSULATION ?
60
WHAT ARE METHODS ?
61
HOW TO USE METHODS ? GIVE EXAMPLE.
• For example:
62
WHAT ARE ARGUMENT’S IN PYTHON?
64
HOW TO USE WITH ARGUMENTS?
65
WHAT ARE LOGIC FLOWCHARTS ?
(Intuitive understanding of code flow)
66
WHAT IS DIAGRAMATICAL REPRESENTATION OF A FLOW CHART ?
67
WHAT IS PSEUDOCODE ?
• Pseudocode is a method of planning which enables the
programmer to plan without considering about the
syntax.
• It has no syntax like any of the programming language
and thus can’t be compiled or interpreted by the
computer.
68
WHAT IS LIST COMPREHENSION ?
• List comprehension offers a shorter syntax when you want to
create a new list based on the values of an existing list.
For Example:
69
HOW USE CASE VS LOOPS WORK ?
70
HOW FUNCTIONS WORKS WITH RETURN ITEMS ?
def fun():
statements
return [expression]
71
Thank You
https://www.careerera.com 72