long int ( ).
.
7.4
. .
, ,
Unicode, .
Python 3 ASCII-, Unicode (
) ASCII. ASCII,
str.encode("ascii"). StackOverflow.
Unicode.
, -
Python. ,
Python.
1 literal . ; (. ). (. .)
7.4.1
, , , ' -
'. , .
7.4.2
, . ,
"What's your name?".
7.4.3
("""
''').
. :
''' . .
.
"What's your name?", - .
: "Bond, James Bond."
'''
7.4.4
, .
, .
, .
7.4.5
, Python -
. , 'What\'s ' 'your name?' "What's your
name?".
C/C++
Python char (). , ,
.
7.4.6 format
- . - -
format().
str_format.py:
age = 26
name = 'Swaroop'
print (' {0} -- {1} .'.format(name, age))
print (' {0} Python?'.format(name))
:
$ python str_format.py
Swaroop -- 26 .
|
|
Swaroop Python?
:
, format .
, {0}, name, format. , {1} age, format. , Python 0, 0, 1 ..
, : '' + name + ' -- ' + str(age) + ' .', , , . - , format , . -, format, , , .
, . :
age = 26
name = 'Swaroop'
print (' {} -- {} .'.format(name, age))
print (' {} Python?'.format(name))
, .
format Python . , :
>>> # (.) 3 :
... '{0:.3}'.format(1/3)
'0.333'
>>> # (_) (^) 11:
... '{0:_^11}'.format('hello')
'___hello___'
>>> # :
... '{name} {book}'.format(name='Swaroop', book='A Byte of Python')
'Swaroop A Byte of Python'
Python
PEP 3101.
7.5
. -
.
, , , .
, .
, - ,
.
7.6
. , - - . :
( ASCII , Unicode), (_).
( ASCII , Unicode), (_) (0-9).
. , myname myName . n N .
: i, __my_name, name_23, a1b2_c3 __utf8_δξѪӆΞέά.
|
|
: 2things, , my-name, >a1b2_c3 "__".
7.7
, . , . , .
7.8
, Python , , . , . , , .