LoginSignup
0
0

More than 5 years have passed since last update.

pyファイルの書き方

Last updated at Posted at 2017-12-14

pyファイルの書き方

バージョン3をベースに記載していきますが、冒頭は2でも3でも同じです。
基本的なファイルのパスやエンコード指定は下記の冒頭2行となります。
importはファイル内のどこでもかまいませんが、一般的には冒頭に記載します。
(今回のサンプルにはimportは必要ありません。)

base_sample.py
#!usr/bin/python
# -*- coding: UTF-8 -*-
import sys, os

print('Hello Python!')
# python3 base_sample.py
Hello Python!

補足:バージョン2のprint関数の場合はprint 'Hello Python!'となります。

base_sample.py
#!usr/bin/python
# -*- coding: UTF-8 -*-
import sys, os

print 'Hello Python!'
# python base_sample.py
Hello Python!

インデックス

前回:Pythonインストール  次回:基本構文

Topのインデックスに戻る 

0
0
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
0
0