. , , . input() print .
, str . , , rjust . help(str) .
/ . , , .
_.py :
def ():
return [::-1]
def _():
return == ()
= input(" : ")
if _():
print(", ")
else:
print(", ")
:
$ python3 _.py
: -
,
$ python3 _.py
:
,
$ python3 _.py
:
,
$ python3 _.py
: -
,
, . [:] , . . 1 , . , -1 , .
input() , . , . , input() .
, . , .
: ; , . TACE16 . TACE16 . , ( , , ) . , , .
, TACE16 247 . , ( , , ) . , TACE16 . , ; . , TACE16- , , .
, , . , "Rise to vote, sir." , . ?
, ...1
, read, readline write , . , . , , , close .
(__.py ):
= '''\
:
!
'''
# 'w' ()
= open('.txt', 'w')
#
.write()
#
.close()
# ,
# 'r' ()
= open('.txt')
while True:
= .readline()
#
if len() == :
break
#
# .
print(, end='')
#
.close()
:
$ python3 __.py
:
!
open . open , , ( ). , ('r'), ('w') ('a') . ('t') ('b') , . , help(open) . , open() , .
, /, write , close .
, . ' ' , . readline , . , . , , ''.
, close .
.txt readline .
pickle , , . .
(_.py ):
import pickle
#
__ = '.'
#
= ['', '', '']
#
= open(__, 'wb')
#
pickle.dump(, )
.close()
#
del
#
= open(__, 'rb')
#
= pickle.load()
print()
.close()
:
$ python _.py
['', '', '']
, w b open , pickle dump . .
, pickle load . .
, , , . ( ), 3 ( , ) .
: 2- , ,
, u , ..u" "
>>> " "
' '
>>> type(" ")
<class 'str'>
>>> " "
' '
>>> type(" ")
<class 'str'>
, . . UTF-8 . open , UTF-8 .
import io
= io.open(".txt", "wt", encoding="utf-8")
.write(" ")
.close()
= io.open(".txt", encoding="utf-8").read()
print()
io.open encoding , . .
: 2- , (
u ) , UTF-8 , # encoding=utf-8 .
, :
- " ."
-
-
/, , .
, .
1. ( ), , = (!,?,., ...). ↩