1.1 Getting Started with Python

1-1 Introduction to Python

One of the nice things about Python is that you can type directly into the ** interactive interpreter **.

** Interactive interpreter ** is a code written in a programming language that is translated into machine language by reading one line and executed, and translated by reading one line so that one question is returned when one question is asked. It is a method of sequential translation called execution.

You can access the Python interpreter using a simple graphical interface called the Interactive DeveLopment Environment (** IDLE **). You can find it in Applications → MacPython on Mac and in All Programs → Python on Windows. If you can't run the Python interpreter, it's probably because Python isn't installed correctly. See here for detailed instructions.

Operate with Python

The prompt reappears when the interpreter completes the calculation and display of the answer. This means that the Python interpreter is waiting for another instruction. (Prompt means ">")

>>>1 + 5 * 2 - 3
8
>>>

You can use an asterisk (*) for multiplication, a slash (/) for division, and () to enclose the expression in parentheses. The above example shows how to work interactively with the Python interpreter and experiment with different expressions in the language to see how they work.

Example error statement

>>> 1 +
  File "<stdin>", line 1
    1 +
      ^
SyntaxError: invalid syntax
>>>

This caused a syntax error. In Python, it doesn't make sense to end an instruction with a plus sign. The Python interpreter indicated the line where the error occurred as ** line 1 **, and the error occurred on the first line. Will tell you.

Now that you have the Python interpreter available, you're ready to start working with your language data.

1-2 Introduction to NLTK

How to install NLTK

Before you can proceed further, you need to install NLTK 3.0, which can be downloaded for free from here. Follow the instructions there to download the version you need for your platform.

NLTK is an abbreviation for Natural Language Tool Kit, which is a library implemented in Python for natural language processing. The feature is that you can play with English by default.

After installing NLTK, launch the Python interpreter, enter the following two commands at the Python prompt to install the required data for the book, and select the collection of books as shown in Figure 1.1. nltk-downloader.png

Figure 1.1: Download NLTK Book Collection: Use nltk.download () to browse for available packages. The downloader's Collection tab shows how packages are grouped into sets. You need to select the line labeled Book to get all the data you need for the examples and exercises in this book.

How to use NLTK

Once the data is downloaded to your PC, you can use the Python interpreter to load some of it. The first step is to enter a special command at the Python prompt.

:from nltk.book import *。

It tells the interpreter to load the text to explore and says "load all items from the NLTK book module". This module contains all the data you need to read this chapter. The command is shown again with the output displayed here. Be careful to get the spelling and punctuation correctly.

>>> from nltk.book import *
*** Introductory Examples for the NLTK Book ***
Loading text1, ..., text9 and sent1, ..., sent9
Type the name of the text or sentence to view it.
Type: 'texts()' or 'sents()' to list the materials.
text1: Moby Dick by Herman Melville 1851
text2: Sense and Sensibility by Jane Austen 1811
text3: The Book of Genesis
text4: Inaugural Address Corpus
text5: Chat Corpus
text6: Monty Python and the Holy Grail
text7: Wall Street Journal
text8: Personals Corpus
text9: The Man Who Was Thursday by G . K . Chesterton 1908
>>>

text1: Herman Melville 1851 "Moby Dick" text2: Senses and sensibilities by Jane Austen 1811 text3: Genesis text4: Inaugural Address Corpus text5: Chat Corpus text6: Monty Python and the Holy Grail text7: The Wall Street Journal text8: Personal Corpus text9: Thursday man by G. K. Chesterton 1908

Whenever you want to know about these texts, you can look them up by simply typing their name at the Python prompt.

>>> text1
<Text: Moby Dick by Herman Melville 1851>
>>> text2
<Text: Sense and Sensibility by Jane Austen 1811>
>>>

You can now use the Python interpreter to process some data.

Recommended Posts

1.1 Getting Started with Python
Getting Started with Python
Getting Started with Python
Getting Started with Python Functions
Getting Started with Python Django (1)
Getting Started with Python Django (4)
Getting Started with Python Django (3)
Getting Started with Python Django (6)
Python3 | Getting Started with numpy
Getting Started with Python Django (5)
Getting Started with Python responder v2
Getting Started with Python Web Applications
Getting Started with Python for PHPer-Classes
Getting Started with Python Basics of Python
Getting Started with Python Genetic Algorithms
Getting started with Python 3.8 on Windows
Getting Started with Python for PHPer-Functions
Getting started with Android!
Getting Started with Golang 2
Getting started with apache2
Getting Started with Golang 1
Getting Started with Django 1
Getting Started with Optimization
Getting Started with Golang 3
Getting Started with Numpy
Getting started with Spark
Getting Started with Pydantic
Getting Started with Golang 4
Getting Started with Jython
Getting Started with Django 2
Getting Started with python3 # 1 Learn Basic Knowledge
Getting Started with Python Web Scraping Practice
Getting Started with Python for PHPer-Super Basics
Getting Started with Python Web Scraping Practice
Getting started with Dynamo from Python boto
Getting started with Python with 100 knocks on language processing
Getting Started with Tkinter 2: Buttons
Getting Started with Go Assembly
Getting Started with PKI with Golang ―― 4
[Translation] Getting Started with Rust for Python Programmers
started python
Getting started with AWS IoT easily in Python
Get started with Python! ~ ② Grammar ~
Getting Started with Django with PyCharm
Materials to read when getting started with Python
Settings for getting started with MongoDB in python
Getting Started with python3 # 2 Learn about types and variables
Getting Started with Google App Engine for Python & PHP
Link to get started with python
Getting Started with Git (1) History Storage
Getting started with Sphinx. Generate docstring with Sphinx
Getting Started with Sparse Matrix with scipy.sparse
Getting Started with Julia for Pythonista
How to get started with Python
Getting Started with Cisco Spark REST-API
Getting started with USD on Windows
Get started with Python in Blender
Getting Started with CPU Steal Time
FizzBuzz with Python3
Scraping with Python
Statistics with python