LoginSignup
1
4

More than 3 years have passed since last update.

ここから始めるpython。起動

Last updated at Posted at 2018-10-10

はじめに

pythonのインストール等はすでに行われているものとします。

環境

anaconda1.8
python3.6
macOS

はじめてのpython

pythonを動かしてみる

macならターミナル(winならコマンドプロンプト)にて
※macの場合、python2が標準搭載されているので注意

$ python
もしくは
$ python3

以下のようになっていたらOKです!

>>>

一番最初のプログラミング。おきまりのhello world。
hello worldと表示されれば成功です。

>>> print('hello world!')
hello world!

以下のようにexit() もしくはctrl+Dで終了することができます。

>>> exit()

また最初の画面で以下のようにも実行できます。

$ python -c "print ('hello world')"
hello world

ちなみに

>>> #プライマリプロンプト
... #セカンダリプロンプト

といいます。これは入力しなくても自動的に表示されます。
こんな風に書けたりします。


>>> a = 4
>>> if a > 3:
...    print("ok")
ok

aが3よりも大きかったらokと表示する処理です。最初にaに4を代入しています。

enterを押すと次のプライマリプロンプトに移ってしまうので
if文などの場合には「:」をつけることでセカンダリプロンプトを
として複数行のコードを書くことができます。

おわり

1
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4