Python CLI or Jupyter Notebook¶
We can use Python CLI or Jupyter Notebook to explore APIs.
We can launch Python CLI using
python
command.We can launch the Jupyter Notebook using the
jupyter notebook
command.A web service will be started on port number 8888 by default.
We can go to the browser and connect to the web server using IP address and port number.
We should be able to explore code in interactive fashion.
We can issue magic commands such as %%sh to run shell commands, %%md to document using markdown etc.
Tasks¶
Let us perform these tasks to just recollect how to use Python CLI or Jupyter Notebook.
Create variables
i
andj
assigning10
and20.5
respectively.
i = 10
j = 20.5
Add the values and assign result to
res
.
res = i + j
print(str(res))
30.5
Get the
type
ofi
,j
andres
.
type(i)
int
type(j)
float
type(res)
float
Get the help on
int
.
help(int)
int?
Init signature: int(self, /, *args, **kwargs)
Docstring:
int(x=0) -> integer
int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments
are given. If x is a number, return x.__int__(). For floating point
numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string,
bytes, or bytearray instance representing an integer literal in the
given base. The literal can be preceded by '+' or '-' and be surrounded
by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
Base 0 means to interpret the base from the string as an integer literal.
>>> int('0b100', base=0)
4
Type: type
Subclasses: bool, IntEnum, IntFlag, _NamedIntConstant
Get the help on
startswith
that is available onstr
.
help(str.startswith)
Help on method_descriptor:
startswith(...)
S.startswith(prefix[, start[, end]]) -> bool
Return True if S starts with the specified prefix, False otherwise.
With optional start, test S beginning at that position.
With optional end, stop comparing S at that position.
prefix can also be a tuple of strings to try.
str.startswith?
Docstring:
S.startswith(prefix[, start[, end]]) -> bool
Return True if S starts with the specified prefix, False otherwise.
With optional start, test S beginning at that position.
With optional end, stop comparing S at that position.
prefix can also be a tuple of strings to try.
Type: method_descriptor