Urchin_learningのPython勉強ブログ

ふと思い立ってPythonを勉強しようと思い立ちました。その勉強日記。

Python 勉強1日目 勉強開始~インストール~VScodeの使い方~文字列の扱い方

全くのプログラミング初心者であるUrchinがPythonを勉強してみます。

なにか勉強してみようと思いプログラミングに行きつきました。

大学時代にウニ(Urchin)を研究していたのでハンドルネームはUrchinです。

会社ではExcelくらいしか触らないのですが、アナログな部分がかなり多い会社なのでこのプログラミングが何かに生かせればと思っています。 

0.勉強開始

参考にするのは以下。

基本的な部分をPython‐izmの流れで勉強し、そのあと入門 Python3の内容に挑もうと思います。

勉強の仕方間違ってたら教えてほしいです。。

 

Python‐izm

www.python-izm.com

 

・入門 Python3

www.amazon.co.jp

 

1.インストール

 下記URLからWindows版のインストーラをダウンロードして、実行。

https://code.visualstudio.com/

インストールが完了したら実行して、

左側のバーから下記3つの拡張機能を検索してインストール

Python

・Japanese Language Pack for Visual Studio Code

・Pylance

 

2.VS codeの使いかた

左のバーの一番上のエクスプローラーで「新しいファイル」を作成

※Urchinは勉強用のフォルダをデスクトップに設置。

 今後はその中にPython File (.py)が格納される。

 

3.文字列の扱い方

上が書いたコード

下が返された値

# 文字列の入力方法
#'' or "" or """(改行するとき)で括ると文字列になる
print('Urchin-izm')
print('Urchin-izm2')
test_str = """
Urchin1
  Urchin2
"""
print(test_str)

#作った文字列に対して +や+= でさらに文字列をくっ付ける
test_str2 = "urchin"
test_str3 = test_str2 + "-"
test_str3 += "izm"

print(test_str3)

#掛け算だと繰り返してくれる
test_str4 = test_str3 * 2

#replace("A","B")で文字列の中の"A"→"B"に書き換えれる
print(test_str4 .replace('izm','ism'))

#split("A")でAも文字でlistに分けることができる
print(test_str3 .split("-"))

#rjust(A,"B")でTotalの文字数がA(数字)分になるように"B"を左側に埋め込む
test_str5 = "0123"
print(test_str5 .rjust(20,"-"))
#ljustは右に埋め込むと思う

#zfill(A) でTotalの文字数がA(数字)分になるように左に0を埋め込む
print(test_str5 .zfill(20))

#startswith("A"),endswith("A")で始まりor終わりが"A"になっているかをT/Fで返す
print(test_str3 .startswith("urchin"))
print(test_str3 .startswith("izm"))
print(test_str3 .endswith("uchin"))
print(test_str3 .endswith("izm"))

#upper("A"),lower("A")は"A"を大文字・小文字化してくれる
test_str6 = "abcdefg"
test_str7 = "HIJKLMN"
print(test_str6 .upper())
print(test_str7 .lower())

#lstrip("A"),rstrip("A")で左or右から"A"を除去 Aを入れなければ空白を消す
test_str8 = "   abc  def  ghi  jkl   "
test_str8 = test_str8 .rstrip()
print(test_str8)
test_str8 = test_str8.lstrip()
print(test_str8)
test_str8 = test_str8.lstrip("abc")
print(test_str8)
test_str8 = test_str8.rstrip("jkl")
print(test_str8)
test_str8 = test_str8.strip()
print(test_str8)
test_str8 = test_str8.strip("def")
print(test_str8)
test_str8 = test_str8.rstrip()
print(test_str8)
test_str8 = test_str8.rstrip("i")
print(test_str8)
test_str8 = test_str8.lstrip("  g")
print(test_str8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

f:id:Urchin_learning:20210505114800p:plain

このへんは問題なく理解できた。と思う。

次は数字の扱い方。