小菜鳥のpython進級の道--------python 3の特徴(フォーマット、注釈、入出力、内蔵関数)
2639 ワード
pythonフィーチャーフォーマット 注記 入出力 内蔵関数
1.フォーマット
2.コメント
3.入力 getpassモジュールのgetpass関数は、入力を非表示にすることができます
input()関数で、入力のデフォルトタイプは文字列 です.
注意:python 2とpython 3の入力の違い python 2のinput()とraw_input()の2つの入力関数、inputのデフォルト入力タイプはint,raw_input()のデフォルト入力タイプは文字列タイプ です. python 3にはinput() のみ
4.出力のフォーマット%s文字列 %d整形 %f浮動小数点数 %d
%s
%f
5.pythonに組み込まれた方法 min() max() sum() enumerate() zip()
1.フォーマット
1.python3 , _*_coding:utf-8_*_
2.
3.
2.コメント
#print('hello world')
"""
print('hello westos')
print('hi')
"""
3.入力
>>> import getpass
>>> num=getpass.getpass(' :')
:
>>> num
'redhat'
>>> age=input(' :')
:18
>>> age
'18'
>>> type(age)
注意:python 2とpython 3の入力の違い
4.出力のフォーマット
In [1]: name = 'westos'
In [2]: age = 11
In [3]: print('%s %d' %(name,age))
westos 11
In [20]: print('%s 130%.3d' %(name,sid)) ##int 0
redhat 130001
In [21]: print('%s 130%.5d' %(name,sid))
redhat 13000001
%s
In [4]: name = 'redhat'
In [5]: print('%s %d' %(name,age))
redhat 11
%f
n [8]: money = 8576.123123
In [9]: print('%s %f' %(name,money))
redhat 8576.123123
In [10]: money = 7000
In [11]: print('%s %f' %(name,money))
redhat 7000.000000
In [12]: print('%s %.2f' %(name,money)) ##
redhat 7000.00
In [13]: print('%s %.3f' %(name,money)) ##
redhat 7000.000
In [14]: print('%s %.1f' %(name,money))
redhat 7000.0
5.pythonに組み込まれた方法
min()
max()
sum()
# value
for i,v in enumerate('hello')
zip() ##
s1=[1,2,3]
s2=[4,5,6]
for i in zip(s1,s2):
print(i)