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')
In [3]:
print(100)
In [4]:
print([0, 1, 2])
In [5]:
print({'a': 0, 'b': 1, 'c': 2})
In [6]:
print('1.00000')
In [7]:
print(1.00000)
In [8]:
s = 'this is a pen'
print(s)
In [9]:
l = [0, 1, 2]
print(l)
In [10]:
print(l[0])
In [11]:
d = {'a': 0, 'b': 1, 'c': 2}
print(d)
In [12]:
print(d['b'])
In [13]:
f = 1.00000
print(f)
In [14]:
i = 100
print('apple', i, 0.123)
In [15]:
print('apple', i, 0.123, sep='----')
In [16]:
print('apple', i, 0.123, sep='\n')
In [17]:
s = 'Alice'
i = 25
In [18]:
print('Alice is %d years old' % i)
In [19]:
print('%s is %d years old' % (s, i))
In [20]:
print('Alice is {} years old'.format(i))
In [21]:
print('{} is {} years old'.format(s, i))
In [22]:
print('{0} is {1} years old / {0}{0}{0}'.format(s, i))
In [23]:
print('{name} is {age} years old'.format(name=s, age=i))
In [24]:
print('{} is {} years old / {{xxx}}'.format(s, i))
In [25]:
s = 'Alice'
i = 25
In [26]:
print(f'{s} is {i} years old')
In [27]:
number = 0.45
print('{0:.4f} is {0:.2%}'.format(number))
In [28]:
print(f'{number:.4f} is {number:.2%}')
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))
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))
In [33]:
print('abc')
print('xyz')
In [34]:
print('abc', end='---')
print('xyz')
In [35]:
print('abc', end='')
print('xyz')