In [1]:
# print 'this is a pen'
# SyntaxError: Missing parentheses in call to 'print'. Did you mean print('this is a pen')?

In [2]:
print('this is a pen')


this is a pen

In [3]:
print(100)


100

In [4]:
print([0, 1, 2])


[0, 1, 2]

In [5]:
print({'a': 0, 'b': 1, 'c': 2})


{'a': 0, 'b': 1, 'c': 2}

In [6]:
print('1.00000')


1.00000

In [7]:
print(1.00000)


1.0

In [8]:
s = 'this is a pen'
print(s)


this is a pen

In [9]:
l = [0, 1, 2]
print(l)


[0, 1, 2]

In [10]:
print(l[0])


0

In [11]:
d = {'a': 0, 'b': 1, 'c': 2}
print(d)


{'a': 0, 'b': 1, 'c': 2}

In [12]:
print(d['b'])


1

In [13]:
f = 1.00000
print(f)


1.0

In [14]:
i = 100
print('apple', i, 0.123)


apple 100 0.123

In [15]:
print('apple', i, 0.123, sep='----')


apple----100----0.123

In [16]:
print('apple', i, 0.123, sep='\n')


apple
100
0.123

In [17]:
s = 'Alice'
i = 25

In [18]:
print('Alice is %d years old' % i)


Alice is 25 years old

In [19]:
print('%s is %d years old' % (s, i))


Alice is 25 years old

In [20]:
print('Alice is {} years old'.format(i))


Alice is 25 years old

In [21]:
print('{} is {} years old'.format(s, i))


Alice is 25 years old

In [22]:
print('{0} is {1} years old / {0}{0}{0}'.format(s, i))


Alice is 25 years old / AliceAliceAlice

In [23]:
print('{name} is {age} years old'.format(name=s, age=i))


Alice is 25 years old

In [24]:
print('{} is {} years old / {{xxx}}'.format(s, i))


Alice is 25 years old / {xxx}

In [25]:
s = 'Alice'
i = 25

In [26]:
print(f'{s} is {i} years old')


Alice is 25 years old

In [27]:
number = 0.45
print('{0:.4f} is {0:.2%}'.format(number))


0.4500 is 45.00%

In [28]:
print(f'{number:.4f} is {number:.2%}')


0.4500 is 45.00%

In [29]:
i = 255

In [30]:
print('left   : {:<8}'.format(i))
print('center : {:^8}'.format(i))
print('right  : {:>8}'.format(i))
print('zero   : {:08}'.format(i))
print('bin    : {:b}'.format(i))
print('oct    : {:o}'.format(i))
print('hex    : {:x}'.format(i))


left   : 255     
center :   255   
right  :      255
zero   : 00000255
bin    : 11111111
oct    : 377
hex    : ff

In [31]:
f = 0.1234

In [32]:
print('digit   : {:.2}'.format(f))
print('digit   : {:.6f}'.format(f))
print('exp     : {:.4e}'.format(f))
print('percent : {:.0%}'.format(f))


digit   : 0.12
digit   : 0.123400
exp     : 1.2340e-01
percent : 12%

In [33]:
print('abc')
print('xyz')


abc
xyz

In [34]:
print('abc', end='---')
print('xyz')


abc---xyz

In [35]:
print('abc', end='')
print('xyz')


abcxyz