0% found this document useful (0 votes)
3 views

02_01_string-functions-lesson-notes-optional-download_Strings - String Functions

Uploaded by

RAKESH SWAIN
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

02_01_string-functions-lesson-notes-optional-download_Strings - String Functions

Uploaded by

RAKESH SWAIN
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Chapter 6 - Strings

Strings

String Functions

Learning Objectives - String


Functions

Identify the syntax for string functions

Demonstrate how to use the min function

Demonstrate how to use the max function


Min Function

String Functions
String functions are predefined functions that perform an action on a
string. Functions have a specific syntax — function name, parentheses,
and a string (often a variable) between the parentheses. The string
between the parentheses is called a parameter, which is a piece of
information the function requires so it can do its job.

String Function Syntax

In fact, len is a string function. There are a few other functions that work
with strings.

The Min Function


The min function returns the “smallest” character from a string. Often
times this is the character that appears first in alphabetical order. When
characters are numbers and symbols, things are not so clear.
my_string = "abcdefghijklmnopqrstuvwxyz"
print(min(my_string))

challenge

What happens if you:


Change my_string to "AaBbCcDd"?
Change my_string to "The brown dog jumps over the lazy fox."?

Note
The program does not have an error. You do not see anything because
the “smallest” character is the " " between words. You cannot easily see
a blank space on its own, which is why it seems like there is a problem
with your code.

Change my_string to "@<#$%!^&*="?


Max Function

The Max Function


The max function is the opposite of the min function. Instead of returning
the “smallest” character, it returns the “biggest”.

my_string = "xyz321"
print(max(my_string))

challenge

What happens if you:


Change my_string to "123^&$"?
Change my_string to "99 abc"?
Change my_string to "AaBbCcDd"?

You might also like