Lecture-04 (Python Practical Class-02)
Lecture-04 (Python Practical Class-02)
➢ For Example:
name = "John"
age = 30
➢ For Example:
name = "John"
age = 30
4
String Methods
➢ You should never expect your user will cooperate as
intended. Therefore, you will need to ensure that the input of
your user is corrected or checked.
➢ It turns out that built into strings is the ability to use
different types of methods.
➢ Some popular methods are:
➢ strip()
➢ capitalize()
➢ title()
➢ lower()
➢ upper()
➢ replace()
➢ More can be found in:
5
https://docs.python.org/3/library/stdtypes.html#str
Comments
#
➢ Comments are a way for programmers to track what they are
doing in their programs and even inform others about their
intentions for a block of code.
➢ In short, they are notes for yourself and others that will see your
code.
➢ Pseudocode is an important type of comment that becomes a
special type of to-do list, especially when you don’t understand
how to accomplish a coding task.
➢ Shortcut in Pycharm: ctrl 0/
6
A Small Problem with Quotation Marks
➢ Notice how adding quotation marks as part of your
string is challenging.
➢ print("hello,"friend"") will not work and the compiler
will throw an error.
➢ Generally, there are two approaches to fixing this.
First, you could simply change the quotes to single
quote marks.
➢ Another, more commonly used approach would be
code as print("hello, \"friend\""). The backslashes tell
the compiler that the following character should be
considered a quotation mark in the string and avoid a
compiler error.
7
Parameters
➢ Parameters are the placeholders or variables defined in
the function signature that represent the data that a
function expects to receive when it is called.
➢ They act as local variables within the function, and
their values are provided when the function is called
with arguments.
➢ Parameters are defined when you create a function and
are used to specify the input the function expects to
work with.
8
Arguments
➢ Arguments are the actual values or expressions that
are passed to a function when it is called.
➢ When you call a function, you provide the arguments
to match the parameters defined in the function
signature.
➢ The order and number of arguments you pass during
the function call must match the order and number of
parameters defined in the function.
9
Parameters vs Arguments
➢ Parameters:
➢ Arguments
result = add_numbers(5, 10) # Here '5' and '10' are
arguments
10
Parameters: print() Function
Check out the following website for all the built-in functions
of Python:
https://docs.python.org/3/library/functions.html
11
That’s All
For Today!
12