【随時更新】英語を勉強しながら学ぶ プログラミング言語「Python」のまとめ①(英訳付き)

hauts5124
プログラミング言語「Python」について、日々学んできたことをまとめます(定期的に更新)。英訳と併せて更新していきますので、英語を勉強しながら、一緒にプログラマーを目指しましょう!

Pythonとは


https://matome.naver.jp/odai/2154668187254772301/2154668288655211803

■概要

Python(パイソン):オープンソースのプログラミング言語
開   発   者:Guido van Rossun(グイド・ヴァン・ロッサム)
由      来:英国コメディーグループ 「モンティ・パイソン」
特      徴:コードの読みやすさを重視した言語
作 れ る も の :①WEBアプリ( 例:youtube / Instagram / evernote)
②データ解析/分析ツール
(例:graph-tool (グラフ操作・統計解析) /Numpy (数値計算・データ操作) )
③人工知能( 例:Pepper (ソフトバンクのロボット)

■Pythonの人気度 (The Popularity of Python)

IEEE(アイ・トリプル・イー)の記事によると、
47言語の中でパイソンは、2018年最も人気のある言語であることがわかる。

According to “Interactive: The Top Programming Languages 2018”,
the popularity of Python in 2018 has maintained its grip on the No. 1 spot in 47 languages.

■Pythonが支持される理由 (The reason why people choose Python)


https://matome.naver.jp/odai/2154668187254772301/2154668288655212503

① 組み込み言語であること(Python is an embedded language)

CPUやメモリの負荷を軽減することができる。

To avoid the overhead of evaluating code on the fly on machines with limited processing power and memory.

②ライブラリーが優秀であること(High-quality Python libraries)

統計や機械学習の分野において、R言語よりも柔軟性がある。

Python has more flexibility than R language for both statistics and machine learning.

■まとめ (Summary)

WEBアプリ、データ解析/分析ツール、人工知能が作れる。

Python is a programming language for building web application,data analysys /analysis tool,
and artificial intelligence(AI).

47言語中、パイソンは最も人気のある言語である。

Python is the most popular programming language in 47 languages in 2018.

組み込み言語で、ライブラリーが優秀なため、支持されている。

People choose Python because of an embedded language with high-quality libraries.

Pythonの基礎知識について

■コメントとは (What do ” Comments” mean in Python ?)

コード中の1行(または行の一部)に書かれた自然言語(英語etc)。
ある記号以降の文字列を「コードではない」とみなすことができる。

Comments are natural languages in a line of code( or a part of a line).They are regarded as
“They are not code” for subsequent character strings following a symbol.

■コメントの使い方

①1行の場合:文頭にハッシュタグ(#)をつける

Comments in Python start with the hash character, ” # “.

②複数行の場合:シングル(”’ ”’) ・ダブルクオーツ(“”” “””)を使う
※クオーツの使い分けは、ルール化すると良いみたいです。

Use single or double quotes to the beginning and the end.

誰かがコードを読んだ時に何をしているのかを理解し易くするためにコメントを残す。

Programmers leave some comments and indicate what they do for readers.

参考例(some examples below)


https://matome.naver.jp/odai/2154668187254772301/2154668330255258303

https://matome.naver.jp/odai/2154668187254772301/2154668330355258403

■まとめ (Summary)

コメントは、ある記号以降の文字列を「コードではない」とみなすことができる。

Comments are regarded as “They are not code” for subsequent character strings following a symbol.

誰かがコードを読んだ時に、何をしているのかを理解し易くするためにコメントを残す。

For someone who reads code, programmers often leave comments.

1行の場合は、ハッシュタグ(#)、複数行の場合は、クオーツ( ”’ ”’ または “”” “””)を使う。

Use hashtag(#) for single line. As for multiple lines, use single or double quotes.

■print関数とは (What does ” print function” mean in Python?)

画面やテキストストリームのファイルに対し、文字列を出力する関数

The print() function prints the given objects to the standard output device
(screen) or to the text stream file.

■print関数の使い方

①基本構文 ( Basic Syntax ) →( )内に出力したい文字列を入力する。

( )内に出力したい文字列を入力する。

Print the objects in parentheses( ).


https://matome.naver.jp/odai/2154668187254772301/2154674564674352803

https://matome.naver.jp/odai/2154668187254772301/2154674564674354103

② print関数の変数一覧 ( The list of print () patameters )

1) オブジェクト ( Object )

操作対象のデータ、またはデータ(属性)と機能(手続き)を 一纏めにした対象

Object refers to a particular instances of a class, where the object can be a combination of variables, functions, and data structures.

*(アスタリスク)により、1つ以上のオブジェクトがあることを示す場合がある。
(* indicates that there may be more than one object in some cases.)

* indicates that there may be more than one object in some cases.

2) セパレート( Separate / sep )

sep によって、オブジェクトが分割される

objects are separated by sep.

3) エンド ( end )

end を空の文字列(‘ ‘)とすれば、末尾を改行しない様にできる。

‘end’ is ‘ \n ‘, the new line character. You can end a statement with any characters / strings using this parameter.

4)ファイル( file )

write( string )メソッドを持つファイルオブジェクトを出力先として、「file引数に渡す + print( )を使用し、データをファイルに書き込むことができる。

File objects with write method that you can write some data to file by passing file arguments and using print ( ) as the output.

5) フラッシュ( flush )

強制的にprint( )で文字列を出力させることができる。

‘flush’ allows prints to mandate that text be flushed through the outputstream immediately to any waiting recipients.

③print関数の構文・例文

1) print関数の基本構文 ( The full syntax of print() is below )


https://matome.naver.jp/odai/2154668187254772301/2154675107875913403

https://matome.naver.jp/odai/2154668187254772301/2154675109975922003

https://matome.naver.jp/odai/2154668187254772301/2154675111675927003

※上記例文について、随時更新していきたいと思います。

■まとめ (Summary)

print関数とは、画面やテキストストリームのファイルに対し、文字列を出力する関数

The print function prints the objects in parentheses( ).

print関数は、( )内に出力したい文字列を入力する

The print() function prints the given objects to the screen or to the textstream file.

必要に応じて、print関数の上記変数を利用し、文字列を出力できる。

If necessary, you can make use of those parameters above and print objects.

■ オブジェクトとは ( What is an ” object ” in Python? )

変数に代入、あるいは、引数として関数に渡すことができるモノ。

Object is an encapsulation of variables and functions into a single entity.

◆ 参考例 ( Reference example )

変数にインスタンスオブジェクト(整数/文字列/リスト)を代入した例
※インスタンス(instance) :実体

Examples which assign instance objects( integer / string / list ).


https://matome.naver.jp/odai/2154668187254772301/2154682027197407403

■ インスタンスオブジェクトの属性 ( Instance object attributes )

インスタンスオブジェクトは、大きく2種類の属性に分けられる。

There are roughly two types of attributes as for instance objects.

◆参考例:

①データ型:インスタンス変数( instance variables)

データ属性を宣言する必要はない

No need to be declared.

②メソッド:リストオブジェクト( append / insert / remove / sort )

オブジェクトに “属している” 関数

Functions, which belong to objects


https://matome.naver.jp/odai/2154668187254772301/2154682010297378203

■ オブジェクトの種類 ( Object Types )

オブジェクトには、ミュータブルとイミュータブルの2種類がある。

Objects are categorized by “mutable” and “immutable”.

①ミュータブル(mutable/変更可能)

例:リスト / セット / 辞書

Examples: list / set / dictionary

◆参考例①:ユーザ定義のクラス( User definition of class)


https://matome.naver.jp/odai/2154668187254772301/2154682046797445903

◆参考例②:リスト( List )


https://matome.naver.jp/odai/2154668187254772301/2154682046897446003

②イミュータブル( Immutable / 変更不可能 )

例:タプル / フローズンセット / 数値型 / 文字列 / ブール型

Examples: tuple / flozenset / numeric type/ string / bool

◆参考例:文字列( String )


https://matome.naver.jp/odai/2154668187254772301/2154682056097452203

■まとめ

オブジェクト:変数に代入・引数として関数に渡すことができるモノ

Object is an encapsulation of variables and functions into a single entity.

オブジェクトは、データ・メソッドの2属性に分かれる

Objects are roughly two types of attributes: “Data” and “Method” .

オブジェクト種類:ミュータブルとイミュータブルの2種類

Objects are categorized by “mutable” and “immutable”.

■ データ種類 ( Types of data in Python )

①整数 (integer/int)

対象:0、正・負数(小数点を含まない)

Subjects: 0, positive and negative figures


https://matome.naver.jp/odai/2154668187254772301/2154703759076845703

https://matome.naver.jp/odai/2154668187254772301/2154703759176845803

https://matome.naver.jp/odai/2154668187254772301/2154703759176845903

②文字列(string/str)

対象:代入した数値、文字、記号など

Subjects: the assigned integer, string, and symbol.etc.

・特殊文字の使用や、改行、三重クオートする場合のコードを記載する。

Indicate the use of special character, new line, triple quotes.

・シングル(‘ ‘)またはダブルクオーツ(” “)で文字列を囲み、代入すること

Surround strings with single or double quotes when you assign.


https://matome.naver.jp/odai/2154668187254772301/2154703776376905603

https://matome.naver.jp/odai/2154668187254772301/2154703776476905703

https://matome.naver.jp/odai/2154668187254772301/2154703776476905803

https://matome.naver.jp/odai/2154668187254772301/2154703776576906003

③浮動小数点(float)

対象:小数点を含む数値は全て

Subjects: all of figures with decimal points


https://matome.naver.jp/odai/2154668187254772301/2154703785076935603

④真偽値(bool)

対象:True or False

真偽を判断するもの (Judge “True” or “False”)


https://matome.naver.jp/odai/2154668187254772301/2154703789376945703

⑤リスト(list)

対象:数値や文字列など(混ぜて代入可能)

Subjects: figures or strings(You can mix and assign both of them)

・カンマ(,)で区切り、[ ]で囲んで値を代入

Assign values with comma” , ” and square bracket “[ ]”.

1 2