First steps with pure Python#
First objects of simple types, first variables, first function calls (with
print())A point on function calls (with
print()andround())
https://python-cnrs.netlify.app/edu/lite/lab/index.html
Function calls#
There are built-in functions and the developers can of course define other functions. To call a function:
print("hello")
hello
Some functions return a result.
round(1.2)
1
It’s common to store the result in a variable:
my_var = round(1.2)
which can then be used:
print(my_var)
1
Dynamically strongly typed: types, objects and variables#
The function type returns the type of an object:
type("hello")
str
type(2)
int
type(2.0)
float
type(2 + 2)
int
type(2 + 2.0)
float
type(True)
bool
Variables are just tags pointing towards objects. New variables can be used when needed. They are not associated with a type but only with an object (which has a type)…
myvar = 1
print(myvar, type(myvar))
1 <class 'int'>
myvar = "hello"
print(myvar, type(myvar))
hello <class 'str'>