ひとり勉強ログ

ITエンジニアの勉強したことメモ

2022-01-01から1ヶ月間の記事一覧

6章 文字列操作【退屈なことはPythonにやらせよう】

# エスケープ文字 spam = 'Say hi to Bob\'s mother.' print(spam) # Say hi to Bob's mother. print("Hello there!\nHow are you?\nI\'m doing fine.") # Hello there! # How are you? # I'm doing fine. # raw文字列 print(r'That is Carol\'s cat.') # Th…

5章 辞書型【退屈なことはPythonにやらせよう】

# 辞書型 my_cat = {'size': 'fat', 'color': 'gray', 'disposition': 'loud'} print(my_cat['size']) print('My cat has ' + my_cat['color'] + 'fur.') # My cat has grayfur. # 辞書とリストの比較 spam = ['cats', 'dogs', 'moose'] bacon = ['dogs', 'm…

4章 リスト【退屈なことはPythonにやらせよう】

spam = ['cat', 'bat', 'rat', 'elephant'] print(spam[0]) # 'cat' print(spam[1]) # 'bat' print(spam[2]) # 'rat' print(spam[3]) # 'elephant' print(['cat', 'bat', 'rat', 'elephant'][3]) # 'elephant' print('Hello ' + spam[0]) # 'Hello cat' prin…

3章 関数【退屈なことはPythonにやらせよう】

# 関数 def hello(): # 関数を定義 print('Howdy!') print('Howdy!!!') print('Hello there.') hello() # 関数の呼び出し # パラメータのあるdef文 def hello(name): print('Hello ' + name) hello('Alice') hello('Bob') # 戻り値とreturn文 import random …

2章 フロー制御【退屈なことはPythonにやらせよう】

# if文 # 「Hello, world.」が1回表示されるのみ spam = 0 if spam < 5: print('Hello, world.') spam = spam + 1 # while文 # 「Hello, world.」が5回表示される spam = 0 while spam < 5: print('Hello, world.') spam = spam + 1 # 「あなたの名前」と入…

1章 Python入門【退屈なことはPythonにやらせよう】

print('Hello world') print('What is your name?') my_name = input() print('It is good to meet you, ' + my_name) print('The length of your name is:') print(len(my_name)) print('What is your age?') my_age = input() print('You will be ' + str(…