0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

関数の呼び出し方法と属性の参照方法について

Posted at

はじめに

Pythonの関数の呼び出し方法と属性の参照方法の違いについて
分からなっかので備忘録として記載してます。

※ 順次、追記予定

関数の呼び出し方法について

関数名()()の中に記述する場合は、関数の呼び出しを意味します。
関数はある処理を実行するための手続きであり、()内には関数に渡す引数を指定することができます。
関数はその引数に基づいて特定の処理を実行します。

example.py
print("Hello World")
# Hello World
example.py
def add_numbers(a, b):
    result = a + b
    print(result)

add_numbers(3, 5)
# 8

属性の参照方法について

属性は、オブジェクトが持つデータやメソッドを表現します。
オブジェクトは、Pythonにおいてほとんどのものがオブジェクトとして扱われます。
文字列、数値、リスト、辞書、関数、クラスなど、すべてがオブジェクトです。
属性の参照では、.(ドット)を使用してオブジェクトから属性にアクセスします。

example.py
my_string = "Hello, world!"
upper_string = my_string.upper()
print(upper_string)
# HELLO, WORLD!
  • 解説
  1. my_stringという変数に文字列オブジェクト"Hello, world!"を代入しています。
    この文字列オブジェクトには、さまざまな属性(データやメソッド)が存在します。
    例えば、upper()というメソッドは、文字列を大文字に変換するためのものです。
  2. my_string.upper()という形でメソッドを呼び出しています。
    my_stringはオブジェクトを指し、.の後に属性名であるupperを指定しています。
  3. この呼び出しでは、upper()メソッドが実行され、文字列オブジェクトの内容が大文字に変換されます。その結果をupper_stringという変数に代入し、print()関数を使って結果を表示しています。
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?