from __future__ import division
a = 4
a
4
from sympy import S
b = S(4)
b
4
a / 5
0.8
b / 5
4/5
type(a)
int
type(b)
sympy.core.numbers.Integer
type(2**33)
int
type(2**50)
int
type(2**60)
int
type(2**63-1)
long
int()
0
int(45)
45
int(b)
4
type(int(b))
int
int("12345")
12345
int("12345a")
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-25-baacb0b2c65f> in <module>() ----> 1 int("12345a") ValueError: invalid literal for int() with base 10: '12345a'
17 // 5
3
type(b)
sympy.core.numbers.Integer
b // 5
0
type(b // 5)
sympy.core.numbers.Zero
int(3.565462)
3
int(-3.5)
-3
c = 125.142545
c
125.142545
type(c)
float
c + c
250.28509
type(c+c)
float
type(c + 34)
float
float()
0.0
float(4)
4.0
float('234.12341324')
234.12341324
True, False
(True, False)
True or False
True
False or True
True
True or True
True
False or False
False
True and True
True
False and False
False
False and True
False
True and False
False
not True
False
not False
True
(34 == 30 + 4) and (4 < 2)
False
4 < 2
False
type(True)
bool
bool(0)
False
bool(1)
True
bool(34)
True
bool('asdfas')
True
bool("")
False
a = 'bonjour'
a
'bonjour'
type(a)
str
b = "aujourd'hui"
b
"aujourd'hui"
c = """test je aujourd'hui je dis "yo" a """
print(c)
test je aujourd'hui je dis "yo" a
a
'bonjour'
a[1]
'o'
a[0]
'b'
a[5]
'u'
a[6]
'r'
a[-1]
'r'
a[-7]
'b'
str()
''
str(12341234)
'12341234'
L = [34, 1245, 23465, 145.1345, 'assfda', []]
L
[34, 1245, 23465, 145.1345, 'assfda', []]
L[1]
1245
L[-1]
[]
L.append(34)
L
[34, 1245, 23465, 145.1345, 'assfda', [], 34]
type(L)
list
list()
[]
list('asdfadsf')
['a', 's', 'd', 'f', 'a', 'd', 's', 'f']
list(12341234)
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-95-944a9ade9724> in <module>() ----> 1 list(12341234) TypeError: 'int' object is not iterable
list(str(12341234))
['1', '2', '3', '4', '1', '2', '3', '4']
L
[34, 1245, 23465, 145.1345, 'assfda', [], 34]
L + [1,2,3]
[34, 1245, 23465, 145.1345, 'assfda', [], 34, 1, 2, 3]
L
[34, 1245, 23465, 145.1345, 'assfda', [], 34]
len(L)
7
len('bonjour')
7
L
[34, 1245, 23465, 145.1345, 'assfda', [], 34]
L[1:4]
[1245, 23465, 145.1345]
L = [1,2,3,3,4,4,4,5,5,7,8]
L.count(4)
3
L.count(34)
0
2 in L
True
2345 in L
False
L.index(2)
1
L.index(4)
4
L = [1,2,3,6,7,1,2,3]
L
[1, 2, 3, 6, 7, 1, 2, 3]
L.remove(2)
L
[1, 3, 6, 7, 1, 2, 3]
L.reverse()
L
[3, 2, 1, 7, 6, 3, 1]
L.sort()
L
[1, 1, 2, 3, 3, 6, 7]
range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
range(3, 10)
[3, 4, 5, 6, 7, 8, 9]
range(3,99,5)
[3, 8, 13, 18, 23, 28, 33, 38, 43, 48, 53, 58, 63, 68, 73, 78, 83, 88, 93, 98]
range(3,98,5)
[3, 8, 13, 18, 23, 28, 33, 38, 43, 48, 53, 58, 63, 68, 73, 78, 83, 88, 93]
[n**3 for n in range(11)]
[0, 1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]
[n**3 for n in range(11) if n % 2 == 1]
[1, 27, 125, 343, 729]
for n in range(11):
if n % 2 == 1:
print(n**3)
1 27 125 343 729
L = []
for n in range(11):
if n % 2 == 1:
L.append(n**3)
L = []
for n in range(1,11,2):
L.append(n**3)
L
[1, 27, 125, 343, 729]
from sympy import factor, Eq
from sympy.abc import x
factor(x**2-1)
(x - 1)*(x + 1)
factor(x**3-1)
(x - 1)*(x**2 + x + 1)
factor(x**4-1)
(x - 1)*(x + 1)*(x**2 + 1)
for k in range(2,20):
expr = x**k-1
resultat = factor(expr)
eq = Eq(expr, resultat)
print(eq)
x**2 - 1 == (x - 1)*(x + 1) x**3 - 1 == (x - 1)*(x**2 + x + 1) x**4 - 1 == (x - 1)*(x + 1)*(x**2 + 1) x**5 - 1 == (x - 1)*(x**4 + x**3 + x**2 + x + 1) x**6 - 1 == (x - 1)*(x + 1)*(x**2 - x + 1)*(x**2 + x + 1) x**7 - 1 == (x - 1)*(x**6 + x**5 + x**4 + x**3 + x**2 + x + 1) x**8 - 1 == (x - 1)*(x + 1)*(x**2 + 1)*(x**4 + 1) x**9 - 1 == (x - 1)*(x**2 + x + 1)*(x**6 + x**3 + 1) x**10 - 1 == (x - 1)*(x + 1)*(x**4 - x**3 + x**2 - x + 1)*(x**4 + x**3 + x**2 + x + 1) x**11 - 1 == (x - 1)*(x**10 + x**9 + x**8 + x**7 + x**6 + x**5 + x**4 + x**3 + x**2 + x + 1) x**12 - 1 == (x - 1)*(x + 1)*(x**2 + 1)*(x**2 - x + 1)*(x**2 + x + 1)*(x**4 - x**2 + 1) x**13 - 1 == (x - 1)*(x**12 + x**11 + x**10 + x**9 + x**8 + x**7 + x**6 + x**5 + x**4 + x**3 + x**2 + x + 1) x**14 - 1 == (x - 1)*(x + 1)*(x**6 - x**5 + x**4 - x**3 + x**2 - x + 1)*(x**6 + x**5 + x**4 + x**3 + x**2 + x + 1) x**15 - 1 == (x - 1)*(x**2 + x + 1)*(x**4 + x**3 + x**2 + x + 1)*(x**8 - x**7 + x**5 - x**4 + x**3 - x + 1) x**16 - 1 == (x - 1)*(x + 1)*(x**2 + 1)*(x**4 + 1)*(x**8 + 1) x**17 - 1 == (x - 1)*(x**16 + x**15 + x**14 + x**13 + x**12 + x**11 + x**10 + x**9 + x**8 + x**7 + x**6 + x**5 + x**4 + x**3 + x**2 + x + 1) x**18 - 1 == (x - 1)*(x + 1)*(x**2 - x + 1)*(x**2 + x + 1)*(x**6 - x**3 + 1)*(x**6 + x**3 + 1) x**19 - 1 == (x - 1)*(x**18 + x**17 + x**16 + x**15 + x**14 + x**13 + x**12 + x**11 + x**10 + x**9 + x**8 + x**7 + x**6 + x**5 + x**4 + x**3 + x**2 + x + 1)