0% found this document useful (0 votes)
2 views25 pages

Markdown and Python Basics Guide

Uploaded by

laiaguixeras.s
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)
2 views25 pages

Markdown and Python Basics Guide

Uploaded by

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

Markdown & Python

AI & ML
Dr. Ester Vidaña Vila

GES AI & ML Page 1


Markdown
■ Markdown is a language designed to make creating content simple and keep it easy to
read.
■ In short, you can think of Markdown as a straightforward way of writing.

GES AI & ML Page 2


Summary of commands
■ *This is cursive*
■ **This is bold**
■ ***This is cursive and bold***
■ This is *cursive* and **bold** in the same line
■ To create paragraphs, you can leave an empty line:
Hello world!

Hello word!
■ To create a line break within a paragraph, add two spaces at the end of the last word on
that line.

GES AI & ML Page 3


Summary of commands: lists
* This is a list
* This is a list
* This is a list

1. This is an enumeration
2. This is an enumeration
3. This is an enumeration

GES AI & ML Page 4


Summary of commands: headers

# This is an H1 header

## This is an H2 header

### This is an H3 header

#### This is an H4 header

GES AI & ML Page 5


Summary of commands: links

[Link title]([Link]

GES AI & ML Page 6


Summary of commands: images

<img src=[Link]
width="200">

![Title of the image]([Link]


[Link])

GES AI & ML Page 7


Summary of commands: separation lines

■ To create horizontal lines, you must write three consecutive dashes, usually separated
between them.
---

GES AI & ML Page 8


Exercise (to practice):

■ In a notebook, copy the following text and use markdown to format it.

Markdown
Markdown is a lightweight markup language for creating formatted text using a plain-text editor.
John Gruber created Markdown in 2004 as an easy-to-read markup language.
■ Markdown is widely used for blogging and instant messaging, and also used elsewhere in:
1. online forums,
2. collaborative software,
3. documentation pages, and
4. readme files.
The initial description of Markdown contained ambiguities and raised unanswered questions,
causing implementations to both intentionally and accidentally diverge from the original version.
This was addressed in 2014 when long-standing Markdown contributors released CommonMark,
an unambiguous specification and test suite for Markdown.

GES AI & ML Page 9


Python – Basic operations
■ Addition: +
■ Subtraction: -
■ Multiplication: *
■ Division: /
■ Division quotient: //
■ Remainder of the division: %
■ Exponent: **
■ Comments: #
■ Parentheses are used to give calculation priority to the desired operands
■ Variable assignment: =
■ Strings: ‘ ‘ o “ “.
■ To print to the screen: use the print() function.

GES AI & ML Page 10


Python – data types
■ Lists: used to store multiple items in a single variable.
■ They are declared with [ ], and each element is separated by a comma (,).
■ Lists can be nested within each other.
■ Dictionaries: used to store values as key:value pairs.
■ A dictionary is an ordered, mutable collection that does not allow duplicate keys.
■ They are declared with { }, each key-value pair is separated by a colon (:), and pairs are
separated by commas (,).
■ Example: {“key1":“value1", ”key2”:”value2”}.
■ Tuples: used to store multiple items in a single variable.
■ They are ordered and immutable (once declared, they cannot be modified). Duplicates
are allowed.
■ Tuples are declared with ( ) and elements can be accessed via indices.
■ Sets: used to store multiple items in a single variable.
■ They are unordered and immutable (once declared, they cannot be modified). Sets do not
allow duplicate elements.
■ They are declared with { } and elements cannot be accessed by index.

GES AI & ML Page 11


Python – comparison operators

■ Greater than: >


■ Smaller than: <
■ Greater or equal than: >=
■ Smaller or qual than: <=
■ Equal: ==
■ Different: !=

GES AI & ML Page 12


Python – Boolean operators

■ and
■ or

■ They work with Boolean data types:True or False.

GES AI & ML Page 13


Python – flow control

■ For
■ If

■ Example:
■ Exit the loop when x is "banana":

fruits = ["apple", "banana", "cherry"]


for x in fruits:
print(x)
if x == "banana":
break

GES AI & ML Page 14


Python – flow control

■ While
■ If

■ Example:
■ Print a message once the condition is false:

i = 1
while i < 6:
print(i)
i += 1
else:
print("i is no longer less than 6")

GES AI & ML Page 15


Python – methods in lists
Method Description
append() Adds an element at the end of the list
clear() Removes all the elements from the list
copy() Returns a copy of the list
count() Returns the number of elements with the specified value
extend() Add the elements of a list (or any iterable), to the end of the current list

index() Returns the index of the first element with the specified value

insert() Adds an element at the specified position


pop() Removes the element at the specified position
remove() Removes the first item with the specified value
reverse() Reverses the order of the list
sort() Sorts the list

GES AI & ML Page 16


Python – methods in dictionaries
Method Description
clear() Removes all the elements from the dictionary
copy() Returns a copy of the dictionary
fromkeys() Returns a dictionary with the specified keys and value
get() Returns the value of the specified key
items() Returns a list containing a tuple for each key value pair
keys() Returns a list containing the dictionary's keys
pop() Removes the element with the specified key
popitem() Removes the last inserted key-value pair
setdefault() Returns the value of the specified key. If the key does not exist: insert the
key, with the specified value
update() Updates the dictionary with the specified key-value pairs
values() Returns a list of all the values in the dictionary

GES AI & ML Page 17


Python – methods in tuples

Method Description
count() Returns the number of times a specified value occurs in a tuple
index() Searches the tuple for a specified value and returns the position of
where it was found

GES AI & ML Page 18


Python – methods in sets
Method Description
add() Adds an element to the set
clear() Removes all the elements from the set
copy() Returns a copy of the set
difference() Returns a set containing the difference between two or more sets

difference_update() Removes the items in this set that are also included in another, specified set

discard() Remove the specified item


intersection() Returns a set, that is the intersection of two or more sets
intersection_update() Removes the items in this set that are not present in other, specified set(s)

isdisjoint() Returns whether two sets have a intersection or not


issubset() Returns whether another set contains this set or not
issuperset() Returns whether this set contains another set or not
pop() Removes an element from the set
remove() Removes the specified element
symmetric_difference() Returns a set with the symmetric differences of two sets
symmetric_difference_update() inserts the symmetric differences from this set and another
union() Return a set containing the union of sets
update() Update the set with another set, or any other iterable

GES AI & ML Page 19


Python – methods in strings (i)
Method Description
capitalize() Converts the first character to upper case
casefold() Converts string into lower case
center() Returns a centered string
count() Returns the number of times a specified value occurs in a string
encode() Returns an encoded version of the string
endswith() Returns true if the string ends with the specified value
expandtabs() Sets the tab size of the string
find() Searches the string for a specified value and returns the position of where it was found
format() Formats specified values in a string
format_map() Formats specified values in a string
index() Searches the string for a specified value and returns the position of where it was found
isalnum() Returns True if all characters in the string are alphanumeric
isalpha() Returns True if all characters in the string are in the alphabet
isascii() Returns True if all characters in the string are ascii characters
isdecimal() Returns True if all characters in the string are decimals
isdigit() Returns True if all characters in the string are digits
isidentifier() Returns True if the string is an identifier
islower() Returns True if all characters in the string are lower case
isnumeric() Returns True if all characters in the string are numeric
isprintable() Returns True if all characters in the string are printable

GES AI & ML Page 20


Python – methods in strings (ii)
isspace() Returns True if all characters in the string are whitespaces
istitle() Returns True if the string follows the rules of a title
isupper() Returns True if all characters in the string are upper case
join() Converts the elements of an iterable into a string
ljust() Returns a left justified version of the string
lower() Converts a string into lower case
lstrip() Returns a left trim version of the string
maketrans() Returns a translation table to be used in translations
partition() Returns a tuple where the string is parted into three parts
replace() Returns a string where a specified value is replaced with a specified value

rfind() Searches the string for a specified value and returns the last position of where it was found

rindex() Searches the string for a specified value and returns the last position of where it was found

rjust() Returns a right justified version of the string


rpartition() Returns a tuple where the string is parted into three parts
rsplit() Splits the string at the specified separator, and returns a list

GES AI & ML Page 21


Python – methods in strings (iii)
rstrip() Returns a right trim version of the string

split() Splits the string at the specified separator, and returns a list

splitlines() Splits the string at line breaks and returns a list

startswith() Returns true if the string starts with the specified value

strip() Returns a trimmed version of the string

swapcase() Swaps cases, lower case becomes upper case and vice versa

title() Converts the first character of each word to upper case

translate() Returns a translated string

upper() Converts a string into upper case

zfill() Fills the string with a specified number of 0 values at the beginning

GES AI & ML Page 22


Python – list comprehension
■ Offers a compact and shorter syntax to create a new list based on the values
of an existing list.
■ Example:

fruits =["apple", "banana", "cherry", "kiwi", "mango"]

newlist = []
newlist = [x for x in fruits if "a" in x]
for x in fruits:
if "a" in x:
[Link](x)

GES AI & ML Page 23


Python – map
■ map() is a function that returns a map object (an iterator) resulting from
applying a function over a set of iterable data (list, tuple, etc.).
■ Syntax: map(fun, iter)
Where the parameters are:
■ fun : The function that will be executed for each iterable item.
■ iter : The object that will be mapped (list, tuple, etc.)

GES AI & ML Page 24


Python – filter
■ filter() is a function that, given a sequence and a function, evaluates each
element of the sequence to determine whether it meets a condition.
■ Syntax: filter(fun, iter)
Where the parameters are:
■ fun : The function to be applied to each element of the iterable, returning
True or False
■ iter : The iterable object to be filtered (list, tuple, etc.).
■ Returns: an iterable object containing only the elements for which the function
returned True.

GES AI & ML Page 25

You might also like