In [1]:
# print('hello'
# SyntaxError: unexpected EOF while parsing
In [2]:
print('hello')
In [3]:
# for i in range(3)
# print(i)
# SyntaxError: invalid syntax
In [4]:
for i in range(3):
print(i)
In [5]:
n = 100
# if n == 100:
# print('n is 100')
# else:
# print('n is not 100')
# IndentationError: unindent does not match any outer indentation level
In [6]:
n = 100
if n == 100:
print('n is 100')
else:
print('n is not 100')
In [7]:
# import mathematics
# ModuleNotFoundError: No module named 'mathematics'
In [8]:
import math
print(math.pi)
In [9]:
# import math.pi
# ModuleNotFoundError: No module named 'math.pi'; 'math' is not a package
In [10]:
from math import pi
print(pi)
In [11]:
# from math import COS
# ImportError: cannot import name 'COS' from 'math' (/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload/math.cpython-37m-darwin.so)
In [12]:
from math import cos
print(cos(0))
In [13]:
import math
# print(math.PI)
# AttributeError: module 'math' has no attribute 'PI'
In [14]:
print(math.pi)
In [15]:
l = 100
# l.append(200)
# AttributeError: 'int' object has no attribute 'append'
In [16]:
l = [100]
l.append(200)
print(l)
In [17]:
n = '100'
# print(n + 200)
# TypeError: can only concatenate str (not "int") to str
In [18]:
n = 100
print(100 + 200)
In [19]:
# print(float(['1.23E-3']))
# TypeError: float() argument must be a string or a number, not 'list'
In [20]:
print(float('1.23E-3'))
In [21]:
# print(float('float number'))
# ValueError: could not convert string to float: 'float number'
In [22]:
print(float('1.23E-3'))
In [23]:
n = 100
zero = 0
# print(n / zero)
# ZeroDivisionError: division by zero
# print(n // zero)
# ZeroDivisionError: integer division or modulo by zero
# print(n % zero)
# ZeroDivisionError: integer division or modulo by zero
In [24]:
my_number = 100
In [25]:
# print(myNumber)
# NameError: name 'myNumber' is not defined
In [26]:
print(my_number)
In [27]:
l = [0, 1, 2]
# print(l[100])
# IndexError: list index out of range
In [28]:
print(len(l))
In [29]:
print(l[1])
In [30]:
d = {'a': 1, 'b': 2, 'c': 3}
In [31]:
# print(d['x'])
# KeyError: 'x'
In [32]:
print(d['a'])
In [33]:
print(d)
In [34]:
print(list(d.keys()))
In [35]:
print(d.get('x'))
In [36]:
# with open('not_exist_file.txt') as f:
# print(f.read())
# FileNotFoundError: [Errno 2] No such file or directory: 'not_exist_file.txt'
In [37]:
import os
# os.mkdir('data')
# FileExistsError: [Errno 17] File exists: 'data'