Python Basics Python - Home Python - Overview Python - History Python - Features Python vs C++ Python - Hello World Program Python - Application Areas Python - Interpreter Python - Environment Setup Python - Virtual Environment Python - Basic Syntax Python - Variables Python - Data Types Python - Type Casting Python - Unicode System Python - Literals Python - Operators Python - Arithmetic Operator
はじめに 久しぶりにCodeIQで問題を覗いていたら、Python3でのソートについての問題があり、その時に初めてPython3のソートについて勉強したのでここにメモとして記録ておきます。 *何か間違いや、こうした方がいいなどご指摘がありましたらご教授していただければ幸いです。 要素のソート 要素を昇順に並び替える まず、リストに含まれる要素を、昇順に並び替えてみようと思います。 そこで利用するのはsort()というメソッドです。 文字列の場合は文字コードの並び順に、数値であれば数値が小さい順に並び替えられます。 wordList = ["F","A","X"] #文字列のリスト numberList = [4,6,2] #数値のリスト wordList.sort() print (wordList) #出力結果:["A","F","X"] numberList.sort() print
初心に帰ってpythonで色んなものの最大値、最小値を求める方法。max関数、min関数の使い方です。 意外とこういう系のワードで検索してる人が多いっぽいので。 リストとかタプルとか集合型とかまずは一番基本。リスト型とタプル型。ちょっと変わり種で集合型。 >> list = [1, 4, 8, 2] >>> max(list) 8 >>> min(list) 1 >>> tuple = (1, 4, 8, 2) >>> max(tuple) 8 >>> min(tuple) 1 >>> set = {1, 4, 8, 2} >>> max(tuple) 8 >>> min(tuple) 1 ">Copy >>> list = [1, 4, 8, 2] >>> max(list) 8 >>> min(list) 1 >>> tuple = (1, 4, 8, 2) >>> max(tuple
以下の読み込み用テキストファイルを用いて、 text.txt It is meaningless only to think my long further aims idly. It is important to set my aims but at the same time I should confirm my present condition. Unless I set the standard where I am in any level, I'll be puzzled about what I should do from now on. 以下のメソッドを用いた場合の処理を書いてみます。 read() – ファイルを全て読み込み、その文字列データに対して処理を行う readlines() – ファイルを全て読み込み、1行毎に処理を行う readline() – 1行毎
from datetime import datetime as dt tstr = '2012-12-29 13:49:37' tdatetime = dt.strptime(tstr, '%Y-%m-%d %H:%M:%S') strptimeの第二引数は第一引数のフォーマットを渡す。 例えば、 tstr = '2012/12/29 13:49:37'だった場合、 dt.strptime(tstr, '%Y/%m/%d %H:%M:%S') 文字列から日付(date) import datetime tstr = '2012-12-29 13:49:37' tdatetime = datetime.datetime.strptime(tstr, '%Y-%m-%d %H:%M:%S') tdate = datetime.date(tdatetime.year, tdatetime.mo
Python で文字列を別の文字列で置換したいときは replace あるいは re.sub を使います。 replace は単純な文字列置換を行います。正規表現を利用したより複雑な置換を行うためには標準ライブラリの re モジュールにある re.sub を使用します。 replace を使用して文字列を置換する replace の記述方法は以下の通りです。
普通、プログラム言語ではorとand (または||と&&などの類似表現) は (2項の) 論理演算を意味します。 つまりorやandが返す値は bool 値 (True/False) です。 C系の言語では True/False が 1/0 で代用されたりもしますが、とにかく論理演算 or と and は論理値に相当する値を返します。 しかし、Python では、orとandは論理値を返すとは限りません。 Pythonにおいて、式x and yは、次と等価です: if not bool(x): # xの論理値がFalseなら return x # yを見ることなく、しかもFalseではなくxそのものをリターン else: # xの論理値がTrueなら return y # bool(y) ではなく、yそのものをリターン
毎回調べるの面倒なので、Pythonでファイル/ディレクトリ操作する方法をまとめておく。 パスが存在するかチェックする
Source code: Lib/argparse.py Tutorial This page contains the API reference information. For a more gentle introduction to Python command-line parsing, have a look at the argparse tutorial. The argparse module makes it easy to write user-friendly command-line interfaces. The program defines what arguments it requires, and argparse will figure out how to parse those out of sys.argv. The argparse mod
文字列操作の比較表: Ruby, Python, JavaScript, Perl, C++ Ruby, Python, JavaScript, Perl, C++ の文字列操作の比較表を作りました。配列操作の比較表の続編です。間違いなどがあったらご指摘いただけると助かります。 Ruby (String) Python (str) JavaScript (String) Perl C++ (std::string)
第90回 Start Python Clubでの発表資料 「Python機械学習プログラミング」と振り返る機械学習の動向と展望 1. The document discusses various social media and video sharing platforms and tools for integrating them, including YouTube, Twitter, Flickr, iTunes, and Facebook. 2. It mentions several services that allow embedding or sharing content between platforms, such as CDTube for YouTube, ZonTube for Amazon, and amz.ly for shortening Amazon
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く