LoginSignup
2
3

More than 1 year has passed since last update.

独学プログラマーのまとめ その3

Posted at

初めに

本章からより重要度があがった気がする。

4章 関数

  • 関数は1つのことをすべきで、そのことに特化するべき。

  • 関数を呼び出すとは、その関数が必要とする入力値(引数)を渡し、命令を実行し、出力値を返すこと。

  • 関数定義はdefで行いここでも:(コロン)が大事になってくる。

# def [関数名]([引数]):
#     [〜関数定義〜]

def f(x):
    return x * 2
  • 組み込み関数
    • 最初から用意されている関数。前回もprint関数を用いていた。
    • len,str,int,float,などがあり、使いながら覚えるとよい。
    • 必須引数とオプション引数がある。必須引数がないとエラーとなる。
  • スコープ
    • 変数を読み書きできる範囲のこと。グローバル変数、ローカル変数。
  • 例外処理
    • tryとexceptで例外処理が行える。
a = input("type a number:")
b = input("type another:")
a = int(a)
b = int(b) 
try:
    print(a / b)
except ZeroDivisionError: 
    print("b cannot be zero.")

まとめ

例外処理を覚える

2
3
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
2
3