Natural language processing-Section (1)
Natural language processing-Section (1)
4
Installing Anaconda
5
Installing Anaconda
6
Opening Anaconda
7
Opening Jupyter Notebook
8
Opening Jupyter Notebook
9
Having trouble with Anaconda or
Jupyter?
11
Python Data Types
x = 5
print(type(x))
12
Variables
13
Printing a variable or a message
print(this_is_a_string)
14
Accessing items in lists or
dictionaries
Result :
3
Midoriya
15
Arithmetic Operators
Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
** Exponentiation (power)
// Floor division
16
Arithmetic Operators
print(1 + 1)
print(1 – 1)
print(2 * 3)
print(6 / 2)
print(4 % 2)
print(5 // 2)
Result :
2
0
6
3
0
2 17
Conditionals
Result :
This is true 18
Greater than 0
Logical Operators
Operator Equivalent to
and &&
or ||
not !
19
Loops
for i in range(10):
print(“This will loop 10 times”)
for x in this_is_a_list:
print(x)
i = 1
while i < 6:
print(i)
i += 1
21
For Loops
A for loop is used for iterating over a sequence (that is either a list, a
tuple, a dictionary, a set, or a string).
With the for loop we can execute a set of statements, once for each item
in a list, tuple, set etc.
22
Loops ( break and continue )
fruits = i = 0
["apple", "banana", "cherry"] while i < 6:
for x in fruits: i += 1
print(x) if i == 3:
if x == "banana": continue
break print(i)
24
Example
list_of_favorites = [
{“name”: “Ahmed”, “likes”: ”watermelon”},
{“name”: “Michael”, “likes”: “apples”},
{“name”: “Sara”, “likes”: “grapes”}
{“name”: “Mariam”, “likes”: “mango”}
]
25
Try it out yourself
Code:
https://colab.research.google.com/drive/1KmZ7HPJS_Mq
s3IshXf4wsjBZa5VeENat
26
Task #1
27
Task #2
list1=[100,200,300,'A',400,500]
28
Defining functions
def sayHello(name):
print(“Hello, ” + name)
sayHello(“Ahmed”)
Result :
Hello, Ahmed
29
Multiline strings
Result :
To be or not to be
This is the question
30
String slicing
Result :
t
31
String slicing
Result :
Me
It’s-a me, Mario! 32
String slicing
str = “sdetcwryept”
print(str[::2])
Result :
secret
33
String slicing
Result :
!
34
String length
Result :
51
35
Removing extra whitespace on
sides
Result :
There are extra spaces on the sides
There are extra spaces on the sides
36
Replacing characters in a string
Result :
['Split', 'up']
38
String concatenation
Result :
Let’s merge these two strings
39
Opening files
file = open(“text.txt“)
40
Opening files
41
Reading files
file = open(“text.txt“)
print(file.read())
42
Reading files
file = open(“text.txt“)
print(file.readline())
print(file.readlines())
43
Writing files
44
Writing files
45
Closing files
46
Closing files
47
Installing new libraries
48
Installing new libraries
49
Reading PDF files
50
Reading PDF files
import PyPDF2
51
Extracting text from PDF files
To read the text from the PDF file, you first need to get
the page you want to get the text from by using the
getPage() function. After that, you use the
extractText() function.
import PyPDF2
Code:
https://colab.research.google.com/drive/1UAtVuTLbWGg
WSwJvMYILiVTpBXs7HoYv
53
Task #3
54
Task #4
55
Thank you for your attention!
56
References
https://www.freecodecamp.org/news/learning-python-from-zero-to-hero-120ea540b567
/
https://en.wikipedia.org/wiki/Python_(programming_language)
https://www.w3schools.com/python/python_operators.asp
https://www.learnpython.org/en/Basic_String_Operations
https://www.w3schools.com/python/python_strings.asp
https://www.w3schools.com/python/python_file_handling.asp
57