Python Tutorial Notes
Python Tutorial Notes
Variable Type
07/14/2024
A delivery man knocks at your door, carrying a big box for your obsessed shopping sister. As a
bystander, you don't know what's inside. It could be a book, a skincare product, or anything else.
This box represents the variable itself, and its contents represent the values stored within the
variable. Just like you can't predict what's inside the box until you open it, the type of variable
3. String ('str'): This one includes characters, such as text messages or names enclosed in quotes ("
4. Boolean ('bool'): In this box, you find logical values representing true or false statements.
5. List ('list'): Imagine a box that organizes items in order; it can contain different types.
6. Dictionary ('dict'): Pairs of keys (variables) and their associated values, defined by curly braces
({}).
User Input
It's a collection of information about a user, which may include different types of values. We use int
or float if the value is a number, and float for both with and without fractions.
Python Tutorial Notes
Conditionals
07/15/2024
Conditions
Programs use conditions to make decisions based on criteria such as data or user input.
Execution Flow
In if-else or if-elif-else statements, the first true condition's block executes, and subsequent blocks
are skipped.
Organizing Conditions
Comparison Operators
Operators include:
- == for equal to
Indentation
Crucial in Python to define code blocks, ensuring statements like print are executed correctly.
Python Tutorial Notes
07/18/2024
To find the minimum number in a list, use the min() function. Here is an example:
numbers = [3, 1, 4, 1, 5, 9]
print(min(numbers))
# Output >>> 1
To find the maximum number in a list, use the max() function. Here is an example:
numbers = [3, 1, 4, 1, 5, 9]
print(max(numbers))
# Output >>> 9
print("banana" in fruits)
print("orange" in fruits)
Python Tutorial Notes
list1 = [1, 2, 3, 4, 5, 6, 7]
print(combined_list)
numbers = [1, 2, 3, 4, 5, 6]
numbers.pop()
# Output >>> 6
print(numbers)
# List of numbers
numbers = [3, 1, 4, 1, 5, 9]
min_number = min(numbers)
is_three_in_list = 3 in numbers
additional_numbers = [2, 6, 5]
combined_numbers.pop()
Minimum number: 1
ToTo
To sort
sort
sort aa list
alistlist ofof
of numbers
numbers
numbers inin
in Python,
Python,
Python, you
youyou can
can can use
use
use the
thethe sort()
sort()
sort() method.
method.
method. Let's
Let's
Let's correct and
correct
correct and
and
refine
refine
refine your
youryour example
example
example to
to to demonstrate
demonstrate
demonstrate how
howhow to
to to do
dodo this
this
this properly.Here's
properly.Here's
properly.Here's the
thethe step-by-step
step-by-step
step-by-step
To sort
process:Define a
process:Define list of
thenumbers
the list of in Python,
numbers.Use you
the can use
sort() the
method to sort the list in ascending
process:Define the listlist
of of numbers.Use
numbers.Use the the sort()
sort() method
method to to sort
sort thethelistlist
in in ascending
ascending
sort()
order.Printmethod.
order.Print the the Let's
sorted
sorted correct
list.Example#and
list.Example# refine
Defineyour
Define theexample
thelist of numbers
order.Print the sorted list.Example# Define the listlist
of of numbers
numbers
to demonstrate
numbers
numbers = [-1,
= [-1, -2, how
-5, 6,to do
100, this
10, properly.Here's
15] the
numbers = [-1, -2,-2,
-5,-5, 6, 6,100,100,10,10,15]15]
step-by-step process:Define the list of numbers.Use
the sort() method to sort the list in ascending
## Sort
#Sort
Sortthe
thethe list
list listinin
in ascending
ascending
ascending order
order
order
order.Print the sorted list.Example# Define the list of
numbers.sort()
numbers.sort()
numbers.sort()
numbers
numbers =sorted
[-1, -2, -5, 6, 100, 10, 15]
## Print
#Print
Printthe
thethe sorted
sorted list
listlist
print(numbers)Explanationnumbers.sort()
print(numbers)Explanationnumbers.sort()
print(numbers)Explanationnumbers.sort() sorts
sorts
sorts the
the thelist numbers
list
list numbers
numbers inin
in place,
place,
place, meaning
meaning
meaning itit it
# Sort the
changes
changes the the list in ascending
original
original list
listto theorder
changes the original list to sorted order.The print(numbers) statement will then
numbers.sort()
output the sorted list.
# Print the sorted list
print(numbers)Explanationnumbers.sort() sorts the list
numbers in place, meaning it changes the original list
to Important Notes