Session+Presentation+-+Introduction+to+Python
Session+Presentation+-+Introduction+to+Python
[email protected]
XR0S5B9UT4 Python
Agenda
[email protected]
XR0S5B9UT4 Conditional Statements
Looping Statements
Functions
Can be created by assigning a value to it with the “=” operator (assignment operator)
num = 100 => creates a variable num and stores the value 100 in it
num = 3.14 => variable num gets modified, now stores 3.14 instead of 100
This file is meant for personal use by [email protected] only.
Sharing or publishing the contents in part or full is liable for legal action.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Python Fundamentals Quiz
1+7 8
+, - Addition, Subtraction
9-4 5
3*4 12
*, /, % Multiplication, Division, Modulus 6/2 3.0
[email protected]
XR0S5B9UT4 6%2 0
** Exponentiation 2 ** 4 16
A Only List
[email protected]
XR0S5B9UT4
A Only List
[email protected]
XR0S5B9UT4
Which of the following will retrieve the two middle elements from the list?
my_list = [1, "two", 3.5, "four", 5, 6.0, "seven", 8.2]
A my_list[3:5]
[email protected]
XR0S5B9UT4
B my_list[4:6]
C my_list[-5:-3]
D my_list[-4:-6]
This file is meant for personal use by [email protected] only.
Sharing or publishing the contents in part or full is liable for legal action.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Python Fundamentals Quiz
Which of the following will retrieve the two middle elements from the list?
my_list = [1, "two", 3.5, "four", 5, 6.0, "seven", 8.2]
A my_list[3:5]
[email protected]
XR0S5B9UT4
B my_list[4:6]
C my_list[-5:-3]
D my_list[-4:-6]
This file is meant for personal use by [email protected] only.
Sharing or publishing the contents in part or full is liable for legal action.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Lists - Slicing
To retrieve a specific subset of elements from a list, one can slice the list by index
"elif" is used to define a block of code to be executed if the preceding "if" or "elif"
A
condition(s) evaluate to False.
[email protected]
XR0S5B9UT4
C "elif" is used only when there are multiple conditions and no "else" block is present.
"elif" is equivalent to "else if" and can be used interchangeably with the "else"
D
statement.
This file is meant for personal use by [email protected] only.
Sharing or publishing the contents in part or full is liable for legal action.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Python Fundamentals Quiz
"elif" is used to define a block of code to be executed if the preceding "if" or "elif"
A
condition(s) evaluate to False.
[email protected]
XR0S5B9UT4
C "elif" is used only when there are multiple conditions and no "else" block is present.
"elif" is equivalent to "else if" and can be used interchangeably with the "else"
D
statement.
This file is meant for personal use by [email protected] only.
Sharing or publishing the contents in part or full is liable for legal action.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Conditional Statements
if (test expression):
<Body of if> this is executed if the expression is True
[email protected]
XR0S5B9UT4 else:
<Body of else> this is executed if the expression is False
More than one decision can be made using the if-elif-else construct
[email protected]
XR0S5B9UT4for for iter_var in seq: for i in range(1, 5): Prints all integers from 1 till 5
statements(s) print(i) (excluded)
def function_name(parameters):
statement(s)
return statement
Example: Create a function called squared_sum to add the square of two numbers