Unformatted text preview:

UNIT III CONTROL FLOW FUNCTIONS STRINGS Conditionals Conditionals are used to control the flow of execution in a program based on certain conditions 1 Boolean Values and Operators Boolean values True and False Logical operators and or not 2 Conditional Statement if Executes a block of code if a certain condition is true Example 3 Alternative Conditional if else Executes one block of code if the condition is true and another block if it s false 4 Chained Conditional if elif else Evaluates multiple conditions in a sequence Iteration Iteration is the process of repeating a block of code multiple times 1 while loop Example Executes a block of code as long as a certain condition is true 2 for loop Example Iterates over a sequence e g list string range 3 break and continue 4 pass statement break terminates the loop continue skips the current iteration and moves to the next one Does nothing used as a placeholder when a statement is required syntactically but no action needs to be taken Functions Functions are reusable blocks of code that perform a specific task 1 Fruitful Functions Functions that return a value Use the return statement 2 Parameters and Arguments Parameters are variables defined in the function definition Arguments are the values passed to the function when it s called 3 Local and Global Scope Variables defined inside a function have local scope Variables defined outside a function have global scope 4 Function Composition 5 Recursion Combining simple functions to create more complex ones A function that calls itself with a smaller input until a base case is reached Strings Strings are sequences of characters 1 String Slices 2 Immutability Accessing a portion of a string using indexing and slicing Strings are immutable meaning they cannot be modified after creation 3 String Functions and Methods Python provides various built in functions and methods for working with strings 4 String Module The string module provides additional functionality for string manipulation Lists as Arrays Lists in Python can be used as arrays to store and manipulate collections of values Illustrative Programs 1 Square Root 2 Greatest Common Divisor GCD 3 Exponentiation 4 Sum an Array of Numbers 5 Linear Search 6 Binary Search


View Full Document

Anna CS 8791 - UNIT III: CONTROL FLOW, FUNCTIONS, STRINGS

Download UNIT III: CONTROL FLOW, FUNCTIONS, STRINGS
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view UNIT III: CONTROL FLOW, FUNCTIONS, STRINGS and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view UNIT III: CONTROL FLOW, FUNCTIONS, STRINGS and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?