0% found this document useful (0 votes)
11 views28 pages

Session+Presentation+-+Introduction+to+Python

The document is a Python fundamentals quiz designed for personal use, covering topics such as variables, operators, data structures, conditional statements, and looping statements. It includes multiple-choice questions to test knowledge on Python programming concepts. The content is proprietary and unauthorized distribution is prohibited.

Uploaded by

murali.dhiviya96
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views28 pages

Session+Presentation+-+Introduction+to+Python

The document is a Python fundamentals quiz designed for personal use, covering topics such as variables, operators, data structures, conditional statements, and looping statements. It includes multiple-choice questions to test knowledge on Python programming concepts. The content is proprietary and unauthorized distribution is prohibited.

Uploaded by

murali.dhiviya96
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Introduction to

[email protected]
XR0S5B9UT4 Python

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

Variables, Operators, and Data Structures

Agenda
[email protected]
XR0S5B9UT4 Conditional Statements

Looping Statements

Functions

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.
Let’s begin the discussion by answering a few questions
[email protected]
XR0S5B9UT4
on the fundamentals of Python programming

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 is true regarding variables in Python?

A Values assigned to variables can be modified


[email protected]
XR0S5B9UT4

B Variables can store data structures such as arrays and dictionaries

C Variables can only store integer and floats

D Variables can store integer, floats, strings and booleans


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 is true regarding variables in Python?

A Values assigned to variables can be modified


[email protected]
XR0S5B9UT4

B Variables can store data structures such as arrays and dictionaries

C Variables can only store integer and floats

D Variables can store integer, floats, strings and booleans


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.
Variables

Used to store any type of data

Single values (integer, float, string, boolean, etc.)

Data structures (arrays, lists, dictionaries, etc.)


[email protected]
XR0S5B9UT4

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

Can be modified to store a different value

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

Which of the following combinations accurately matches mathematical


symbols with their respective operations?

A + for addition, - for subtraction


[email protected]
XR0S5B9UT4

B * for exponentiation, / for modulus

C % for multiplication, ** for division

D ** for multiplication, % for subtraction


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 combinations accurately matches mathematical


symbols with their respective operations?

A + for addition, - for subtraction


[email protected]
XR0S5B9UT4

B * for exponentiation, / for modulus

C % for multiplication, ** for division

D ** for multiplication, % for subtraction


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.
Operators

Symbol Operation Example Output

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

==, !=, >, >=, <, <= Comparison 5 <= 4 False

in, not in Membership 5 in [1, 2, 3, 4, 5] True

() Grouping (1+2) * (2+3) 3 * 5 = 15


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. 9
Python Fundamentals Quiz

Which of the following data structures in Python are mutable (can be


modified later after being created)?
List, Dictionary, Tuple

A Only List
[email protected]
XR0S5B9UT4

B Tuple and Dictionary

C List and Tuple

D List and Dictionary


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 data structures in Python are mutable (can be


modified later after being created)?
List, Dictionary, Tuple

A Only List
[email protected]
XR0S5B9UT4

B Tuple and Dictionary

C List and Tuple

D List and Dictionary


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.
Data Structures

List Tuple Dictionaries

A collection of items of any data A collection of items of any data


A collection of key-value pairs
type type

Mutable (can be modified)


[email protected] Immutable (cannot be modified) Mutable (can be modified)
XR0S5B9UT4

Syntax: Syntax: Syntax:


mylist = ["Element 1", mytuple = ("Element 1", mydict = {1: 'Element 1', 2:
"Element 2", "Element 3"] "Element 2", "Element 3") 'Element 2', 3: 'Elements 3'}

Example: Example: Example:


X=["a", 2, True, "b"] X=("a", 2, True, "b") X={1:'Jan', 2:'Feb', 3:'Mar'}

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.
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

The format for list slicing is as follows:

<list_name>[Start Index : End Index : Index-Jump]


[email protected]
XR0S5B9UT4
Consider a list my_list = [‘a’, ‘b’, ‘c’, ‘d’]

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 statement accurately describes the behavior of the "elif" construct in


Python?

"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

B "elif" is mandatory and must be included after every "if" statement.

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

Which statement accurately describes the behavior of the "elif" construct in


Python?

"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

B "elif" is mandatory and must be included after every "if" statement.

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

Used to make decisions based on specified rules

A single decision can be made using if-else construct

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

if (test expression 1):


<Body of if> run this if test expression 1 is True
elif (test expression 2):
<Body of elif> run this if test expression 2 is True
else:
<Body of else> run this if none of the above expressions are True
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. 18
Python Fundamentals Quiz

Which of the following statements is true regarding loops in Python?

A The "for" loop requires a condition to be evaluated before execution


[email protected]
XR0S5B9UT4

B The "for" loop iterates through a sequence, executing on each element

C The "while" loop requires a condition to be evaluated before execution

D The "while" loop iterates through a sequence, executing on each element


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 statements is true regarding loops in Python?

A The "for" loop requires a condition to be evaluated before execution


[email protected]
XR0S5B9UT4

B The "for" loop iterates through a sequence, executing on each element

C The "while" loop requires a condition to be evaluated before execution

D The "while" loop iterates through a sequence, executing on each element


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.
Looping Statements

Used to repeat a single statement or a set of statements

Looping Syntax Example Output


statement

[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)

while while condition: i = 1 Prints all integers from 1 till 5


statement(s) while i < 5: (excluded)
print(i)
i += 1

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. 21
Python Fundamentals Quiz

What is the purpose of functions in Python?

A To execute a specific task only once in a program


[email protected]
XR0S5B9UT4

B To combine multiple variables into a single variable

C To break code into modular chunks for reusability and organization

D To declare built-in variables that are predefined in Python


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

What is the purpose of functions in Python?

A To execute a specific task only once in a program


[email protected]
XR0S5B9UT4

B To combine multiple variables into a single variable

C To break code into modular chunks for reusability and organization

D To declare built-in variables that are predefined in Python


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.
Functions

Block of instructions that performs a specific task

Break code into modular chunks which can be reused later

Makes the code more organized and manageable


[email protected]
XR0S5B9UT4

There are two types of functions in Python

Built-in Functions: Pre-defined in Python (print(), len(), sum(), etc)

User-defined Functions: Defined by users to perform a specific task

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 statements about the return statement in Python


is/are true?

A A function can have multiple return statements.


[email protected]
XR0S5B9UT4

B A function can return multiple values in a single return statement

C It returns a value or an expression computed by the function.

D A function must always include a return 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

Which of the following statements about the return statement in Python


is/are true?

A A function can have multiple return statements.


[email protected]
XR0S5B9UT4

B A function can return multiple values in a single return statement

C It returns a value or an expression computed by the function.

D A function must always include a return 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.
User-defined Functions

Syntax for a user defined function:

def function_name(parameters):
statement(s)
return statement

The return statement


[email protected]
XR0S5B9UT4 is optional and can be used when one or more values have to be
returned by the function

Example: Create a function called squared_sum to add the square of two numbers

def squared_sum(num1, num2):


sq_sum = (num1*num1) + (num2*num2)
return sq_sum

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.
Happy Learning !
[email protected]
XR0S5B9UT4

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. 28
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.

You might also like