In [1]:
print('Hello World !')
Two notions:
String = characters enclosed by singles or double quotes
In [3]:
a = 'jesuisunechaine'
b = "moiaussi!!!"
In [4]:
print(a)
print(b)
Strings (which are objects) can be stored into a variable. You name the variable as you want. There is no character type (only 1-length string...)
In [8]:
c = a + b
c = a + b + "..."
You can construct a new string using the add operator which concatenates two (or more) different strings.
In [6]:
a = 3
b = 5.0
In [7]:
print(a)
print(b)
We have numbers. Remarks:
a did switch from string to integer)The print() works with any racism over strings or number (and many more objects). This is a consequence of duck typing: "In other words, don't check whether it IS-a duck: check whether it QUACKS-like-a duck, WALKS-like-a duck, etc, etc, depending on exactly what subset of duck-like behaviour you need to play your language-games with." (Alex Martelli). Formally, the print() function accepts every object that have the function __repr__() implemented. It is kind of ducky enough for it !
In [9]:
print(type(a))
print(type(b))
You can check the type of any objects using the type()function. Prefer isinstance() for program check
You have access to basic math operations:
In [10]:
c = a + 1
d = (a * b) + 2
e = d / a
if
if not
In [ ]: